具有字符+的网址编码/解码问题

时间:2019-03-05 15:49:30

标签: java spring spring-boot urlencode urldecode

我在使用RequestParam获取值时遇到问题,它为“ +”字符返回空字符。 所以我尝试编码该值

@RequestMapping(value = "/get-data", method = RequestMethod.GET)
public User getData(@RequestParam("id") String id) {
    try {
        id= URLEncoder.encode(id, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    LOGGER.info("Incoming request for getting data with ID {}", id);
    return userService.getData(id);
}

在服务中,我尝试对该值进行解码,但无济于事,它再次返回值,其中'+'字符更改为空字符

id = URLDecoder.decode(id, "UTF-8");

值示例:

value in url: gf45dfo+/s)83s68s=
value after encode: gf45dfo+%2Fs%2983s68s%3D
value after decode: gf45dfo /s)83s68s=

有人知道如何解决吗?

0 个答案:

没有答案