关于SpringBoot下template文件夹下html页面访问的一些问题

  • springboot整合了springmvc的拦截功能。拦截了所有的请求。默认放行的资源是:resources/static/ 目录下所有静态资源。(不走controller控制器就能直接访问到资源)。
    • html页面如果放在resources/templates目录下,则需要走controller控制器,controller放行,允许该资源访问,该资源才能被访问到。否则就会报404错误(它不可以直接被访问)。

  • springboot项目中templates包下的html代码无法引入static下的静态文件。
    • 在 .properties中添加:spring.mvc.static-path-pattern=/static/**
  • 关于springboot中thymeleaf的配置:
    spring.mvc.static-path-pattern=/static/**
    spring.thymeleaf.servlet.content-type=text/html
    spring.thymeleaf.mode=HTML
    spring.thymeleaf.cache=false
    spring.thymeleaf.prefix=classpath:/templates/
    spring.thymeleaf.suffix=.html