且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Spring Boot:防止对@RequestParam 进行解码

更新时间:2022-06-12 00:26:45

如果您只需要在一个地方进行这种行为,您可以使用标准 Java URLEncoder 位于控制器主体内部:

If you need this behavior only in a single place, you can encode the parameter back to the original form using the standard Java URLEncoder inside of the controller body:

@RequestMapping("/test")
public ResponseEntity<String> test(@RequestParam final String test) {
  String encodedParam = URLEncoder.encode(test, "UTF-8");
  return ResponseEntity.ok("Requested: " + encodedParam);
}