springboot 跳轉頁面


輸入 127.0.0.1:8080/index 跳轉到對應的頁面

一開始參照博客的里的介紹(如圖),但頁面返回結果 是 test,后來發現 使用的是 @RestController ,換成@Controller,頁面跳轉正確

 

 

正確的跳轉到頁面的方法:

1.application.properties 文件新增如下

1 # 定位模板的目錄
2 spring.mvc.view.prefix=/
3 # 給返回的頁面添加后綴名
4 spring.mvc.view.suffix=.html

 

 

 

 

 

 2.增加html文件,test.html ,如圖

 

 

 

 

 

3.control 文件新增:

1 @Controller
2 class MyControllerPages{
3     @RequestMapping(value = "/index", method = RequestMethod.GET)
4     public String index() {
5         return "test";
6     }
7 }

 

 

 

4.演示:

 

 

 

 

ps:小魚最近每月更新的隨筆很少很少,活有點多,需要多留點時間學習ヾ(◍°∇°◍)ノ゙

 

參考鏈接:

https://www.cnblogs.com/guo-xu/p/11203740.html


免責聲明!

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



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