0
点赞
收藏
分享

微信扫一扫

springboot 跳转页面

岛上码农 2022-08-11 阅读 89

输入 127.0.0.1:8080/index 跳转到对应的页面

一开始参照博客的里的介绍(如图),但页面返回结果 是 test,后来发现 使用的是 @RestController ,换成@Controller,页面跳转正确

 

springboot 跳转页面_mvc

 

正确的跳转到页面的方法:

1.application.properties 文件新增如下

1 # 定位模板的目录
2 spring.mvc.view.prefix=/
3 # 给返回的页面添加后缀名
4

springboot 跳转页面_html_02

 

 

 

 

 

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

springboot 跳转页面_html_03

 

 

 

 

 

3.control 文件新增:

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

springboot 跳转页面_java_04

 

 

 

4.演示:

springboot 跳转页面_java_05

 

 

 

 

ps:小鱼最近每月更新的随笔很少很少,活有点多,需要多留点时间学习ヾ(◍°∇°◍)ノ゙


举报

相关推荐

0 条评论