springboot默认 static中放静态页面,而templates中放动态页面
**注:html链式引入css或js时,路径默认是从static开始的 **
lg : href="/css/mycss.css"

加入thymleaf依赖后,springboot中controller中的跳转页面操作,自动跳转templates下的页面,而不会扫描static下的页面
static
static文件夹默认存放的是静态资源 静态页面
static文件夹中的html页面为静态页面,可以直接在浏览器地址访问xxx.html,如果用controller跳转到该页面的话
@RequestMapping("/totest")
public String totest(){
//返回值的路径要加入.html后缀
return "/test.html";
}
templates
templates文件夹存放的时动态页面(使用了thymleaf模板引擎)
动态页面不能通过浏览器地址直接访问,所以要使用请求进行跳转

@RequestMapping("/tofind")
public String tofind(){
//返回值的路径不需要加入.html后缀
return "/find";
}
注:加入thymleaf依赖后,springboot中controller中的跳转页面操作,只跳转templates下的动态页面,而不能跳转static下的动态页面(个人理解)
本文介绍了SpringBoot中static和templates文件夹的用途。static用于存放静态资源,如css和js,其html页面可直接访问;而templates存放使用Thymeleaf模板引擎的动态页面,需通过控制器跳转。加入Thymeleaf依赖后,Controller只会跳转templates下的页面。

被折叠的 条评论
为什么被折叠?



