我在使用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=
有人知道如何解决吗?