使用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> |