异常:This application has no explicit mapping for /error.以及spring.mvc.view.prefix配置解决
生活随笔
收集整理的這篇文章主要介紹了
异常:This application has no explicit mapping for /error.以及spring.mvc.view.prefix配置解决
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
《Spring Boot實戰派》 實例7實現MVC模式的Web應用程序 遇到的問題
Error resolving template [mvcdemo], template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause主要原因是模板沒找到,說明resource文件可能有問題
第一步:
確保啟動文件的位置,這里是MvcDemoApplication,放在最外側,和子包并列或者處于外側,這里的子包是contrller和model ,spring-boot會自動加載啟動類所在包及其子包下的所有組件
第二步:
需要配置application.properties文件中視圖解析器,筆者這一步出現錯誤
需要配置成如下
Thymeleaf模版默認會使用templates作為視圖文件
第三步
注意@Controller中試圖模板的名字和resource文件下的html文件名字相匹配。
第四步
確保@GetMapping("/mvcdemo")和控制器url訪問路徑一致
參考博客SpringBoot—靜態頁面加載
參考博客異常:This application has no explicit mapping for /error, so you are seeing this as a fallback.
總結
以上是生活随笔為你收集整理的异常:This application has no explicit mapping for /error.以及spring.mvc.view.prefix配置解决的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 编写Thymeleaf视图以展示数据
- 下一篇: 实现MVC模式的Web应用程序