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

原文地址:https://www.cnblogs.com/whycai/p/13701082.html