Springboot中直接访问html


Springboot中直接访问html时
application.properties添加如下配置:
# 定位模板的目录
spring.mvc.view.prefix=classpath:/templates/
# 给返回的页面添加后缀名
spring.mvc.view.suffix=.html
controller返回页面:
@GetMapping("/index")
 public String index(){
   return "home"; //当浏览器输入/index时,会返回 /templates/home.html页面
}
注意:
spring boot默认开启了静态文件的配置,任何放在static文件夹下的资源都是静态文件。引用静态文件时以/或者前缀不加任何定位符,都会去static文件夹下查找。
Thymeleaf模版默认会使用templatess作为视图文件下

猜你喜欢

转载自www.cnblogs.com/cmz-32000/p/11588929.html