Url看起来像:/getUserConnectionsList?login=**********&页面限制=25&page=1&ot=asc&of=打开日期时间§ion=用户活动
@PostMapping(path = "getUserConnectionsList", params = {"login"})
public String getUserConnectionsList(@RequestParam String login,
@RequestParam(required = false) String pagelimit,
@RequestParam(required = false) String page,
@RequestParam(required = false) String from,
@RequestParam(required = false) String to,
@RequestParam(required = false) String ot,
@RequestParam(required = false) String of) {
log.debug("test: {}, {}, {}, {}", login, page, ot, of);
输出看起来像:
测试:**********,1,asc,openDatetime§ion=userActivity
很明显,openDatetime-"§ion";,被解释为HTML实体"§"。但我想知道如何在映射级别解决这个问题,以避免字符串中的字符被转换为我不需要的值时出现进一步的情况。
*该错误可在任何http客户端应用程序上重现。
*使用目前可用的springframework的最新版本2.6.2。
*使用标题内容类型:text/plain;charset=UTF-8
我的猜测是:您在HTML中对URL的编码不正确。请记住,在HTML中,如果&
后面跟着一个有效实体,则&
必须编码为&
。一般来说,你应该一直这样做。
请参阅我是否在<a href>?
示例:
错误:
<form action="/getUserConnectionsList?login=**********&pagelimit=25&page=1&ot=asc&of=openDatetime§ion=userActivity">
</form>
右:
<form action="/getUserConnectionsList?login=**********&pagelimit=25&page=1&ot=asc&of=openDatetime&section=userActivity">
</form>
考虑到您正在使用Spring,您可能正在使用Thymelaf。如果您使用th:action
和@{...}
表达式,它将为您进行编码:
<form th:action="@{'/getUserConnectionsList'(login='**********', pagelimit=25, page=1, ot=asc, of=openDatetime, section=userActivity")}">
</form>