springboot:No mapping for GET /***

阅读: 评论:0

springboot:No mapping for GET /***

springboot:No mapping for GET /***

问题

利用IntelliJ IDEA快速搭建springboot的web系统,前端模板使用thymeleaf。在application.properties和l配置正确、静态资源加载目录无误情况下(hello.html位于templates下),成功启动DemoApplication.java后,在浏览器中访问localhost:8080/test/hello失败,出现Whitelabel Error Page页面、No mapping for GET/test/hello错误。

解决方法

springboot 使用thymeleaf 动态页面跳转静态页面时,需要经过controller层才能实现跳转
添加一个controller,在里面加上hello.html的跳转映射@RequestMapping("/hello")

添加TestController.java

TestController.java

ller;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;@Controller
@RequestMapping("/test")
public class TestController {@RequestMapping("/hello")public String hello() {return "hello";}

正确显示页面

补充学习点

springboot快速搭建web系统
springboot前端模板
springboot整合thymeleaf
springboot之默认首页(欢迎页)的设置
springboot+thymeleaf+layui登录注册demo

hello ! JJ ~

本文发布于:2024-01-29 12:51:52,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170650391415410.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:springboot   mapping
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23