當我們使用ModelAndView進行頁面跳轉出現404,有以下幾個原因:
1.modelAndView包引入錯誤,正確的包應該是( org.springframework.web.servlet.ModelAndView)
2.配置文件中前后綴沒有配置
spring: freemarker: request-context-attribute: request prefix: /templates/ suffix: .html content-type: text/html enabled: true cache: false charset: UTF-8
3.沒有引入相關依賴
缺少:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>