SpringBoot静态资源路径配置及主页显示

网友投稿 282 2023-06-09

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 modelMqDrM){

model.addAttribute("msg", "Hello, Thymeleaf!");

return "index";

}

}

加入模板内容显示首页:

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:详解@Autowired(required=false)注入注意的问题
下一篇:Spring @Valid和@Validated区别和用法实例
相关文章

 发表评论

暂时没有评论,来抢沙发吧~