thymeleaf使用RESTful风格进行单条数据查询、修改信息查询遇到Request method 'GET' not supported解决方案

使用thymeleaf使用RESTful风格进行单条数据查询、修改信息查询遇到

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Mon Apr 08 17:47:47 CST 2019
There was an unexpected error (type=Method Not Allowed, status=405).
Request method ‘GET’ not supported

控制台显示:

Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method ‘GET’ not supported]

分析原因

捣鼓了一下发现在thymeleaf中,传参的方式是在括号中的,比如
<a th:href="@{/user/(id=${u.userId})}">编辑</a>
这样子访问url时解析的出来的是:
http://localhost:8080/user/?id=45623534
但是在RESTful风格中的url应该是这样的
http://localhost:8080/user/45623534
解析出来的url不一致所以才会出现上面的错误

解决方案

将url进行修改,使其解析时符合RESTful风格
具体做法:用+号将url与参数进行连接

改动前改动后
<a th:href="@{/user/(id=${u.userId})}">编辑</a><a th:href="@{/user/}+${u.userId}">编辑</a>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值