springboot 模板可能不存在,也可能不被任何配置的模板解析器訪問。


一、如果返回的是jsp頁面,或者html,@Controller配合視圖解析器InternalResourceViewResolver才行。

 

需要在application.properties配置文件

spring.thymeleaf.prefix=classpath:/templates/

spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=LEGACYHTML5
#spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.content-type=text/html # ;charset=<encoding> is added

spring.thymeleaf.cache=false

 

二、如果需要返回JSON,XML或自定義mediaType內容到頁面,則需要在對應的方法上加上@ResponseBody注解。

 

以上兩者都會報以下錯誤

template might not exist or might not be accessible by any of the configured Template Resolvers

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM