關於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