springboot 跳轉頁面
阿新 • • 發佈:2020-09-20
輸入 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 @Controller2 class MyControllerPages{ 3 @RequestMapping(value = "/index", method = RequestMethod.GET) 4 public String index() { 5 return "test"; 6 } 7 }
4.演示:
ps:小魚最近每月更新的隨筆很少很少,活有點多,需要多留點時間學習ヾ(◍°∇°◍)ノ゙
參考連結: