SpringBoot在寫完Controller之后直接啟動訪問,但是找不到相對應的頁面資源,報404錯誤。
我的Controller編寫沒有錯誤,html文件也放在了templates文件夾下,但是為什么找不到資源呢?
我發現我導入的thymeleaf包不對,請不要導入Maven庫下的thymeleaf包,在SpringBoot中是不會自動配置的。你要導入的是這個包。
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
導入這個包后,啟動,訪問正常。