重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

如何配置SpringBoot静态资源路径

小编这次要给大家分享的是如何配置SpringBoot静态资源路径,文章内容丰富,感兴趣的小伙伴可以来了解一下,希望大家阅读完这篇文章之后能够有所收获。

创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站设计、成都网站建设、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的淮北网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

静态资源路径

静态资源支持放在以下路径中,访问优先级从上到下:

classpath:/META-INF/resources/
classpath:/resources/
classpath:/static/ # 默认路径
classpath:/public/

其中 classpath 为 src/main/resources 目录。

请求地址为:http://localhost:8080/xx.js

首页

文件位置:

classpath:/static/favicon.ico
classpath:/templates/index.html

导入 thymeleaf 模板引擎依赖:


  
    org.springframework.boot
    spring-boot-starter
  
  
    org.thymeleaf
    thymeleaf-spring5
  
  
    org.thymeleaf.extras
    thymeleaf-extras-java8time
  

定义请求控制器:

@Controller
public class IndexController {
  @RequestMapping({"/", "/index.html"})
  public String index(Model model){
    model.addAttribute("msg", "Hello, Thymeleaf!");
    return "index";
  }
}

加入模板内容显示首页:




  
  index page


	

首页

看完这篇关于如何配置SpringBoot静态资源路径的文章,如果觉得文章内容写得不错的话,可以把它分享出去给更多人看到。


新闻名称:如何配置SpringBoot静态资源路径
URL标题:http://cqcxhl.com/article/jgshcs.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP