关于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

     


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM