简体   繁体   English

通过@RequestParam Spring @RestController 解码 url 查询参数时遇到问题

[英]Having a trouble with decoding a url query parameter by @RequestParam Spring @RestController

Url looks like: /getUserConnectionsList?login=**********&pagelimit=25&page=1&ot=asc&of=openDatetime&section=userActivity Url 看起来像: /getUserConnectionsList?login=**********&pagelimit=25&page=1&ot=asc&of=openDatetime&section=userActivity

@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);

And output looks like: output 看起来像:

test: **********, 1, asc, openDatetime§ion=userActivity测试:**********, 1, asc, openDatetime§ion=userActivity

It seems obvious that the following characters after openDatetime - "&sect", are interpreted as HTML ENTITY '§'.很明显,openDatetime 之后的以下字符 - “&sect”,被解释为 HTML ENTITY '§'。 But I would like a know on how to solve this problem at the level of mapping, in order to avoid further situations when characters in a string are converted to a value I do not need.但是我想知道如何在映射级别解决这个问题,以避免在字符串中的字符转换为我不需要的值时出现进一步的情况。

To me it looks like your client side might make an encoding mistake, since the controller code with spring-boot-starter-web 2.6.1 is working fine if I call it with postman.在我看来,您的客户端可能会出现编码错误,因为如果我使用 postman 调用带有 spring-boot-starter-web 2.6.1 的 controller 代码,它工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM