[英]How to not decode the string set by @RequestParam in Spring Boot?
My controller has a method like below: 我的控制器有如下方法:
@ResponseBody
public String test(@RequestParam("r") String r){
String requestURI = request.getQueryString();
// What I want: abc+def%2Cfjg
System.out.println(requestURI.split("=")[1]);
// This is not what I want: abc def,fjg
System.out.println(r);
}
How can I let Spring boot know that the RequestParameter must not be decoded? 如何让Spring Boot知道不能对RequestParameter进行解码? ie not converting + to space, %2C to comma etc..
即不将+转换为空格,不将%2C转换为逗号等。
With the use of decode method you can decode your url. 使用解码方法,您可以解码您的网址。
private String decode(String value) {
String decoded
= URLDecoder.decode(value, StandardCharsets.UTF_8.toString());
return decoded;
}
If you want to encode it then use encode method. 如果要对其进行编码,请使用编码方法。
private String encode(String value) {
String encoded =
URLEncoder.encode(value, StandardCharsets.UTF_8.toString());
return encoded;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.