[英]How to get unknown request parameter in @RequestParam SpringBoot
[英]Springboot : @RequestParam in controller reads the request with '&' and '#' as empty
我有一个在Tomcat上运行的Spring-Boot应用程序。 在其中,我有一个带有请求参数的RestController 。 @RequestParam
不会读取作为查询参数传递的'&'
或'#'
。
例如,如果我输入http://localhost:8080/v1/test?query=&
则控制器方法不将&
作为值
@RequestMapping(value = "/v1/test", method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
public String getV2LocationByName(
@RequestParam
String cityName cityName,
@RequestParam(value = LANGUAGE, defaultValue = US_ENGLISH_LOCALE) String language,
HttpServletRequest request) throws InterruptedException, ExecutionException {
--------------
---------------
System.out.println(cityName);
}
上面的程序为&和#返回空输出
为什么spring限制了这些特殊字符,却没有限制任何其他特殊字符? 另外,如果将查询参数用作“ Andaman&Nicobar”,则查询参数将被读取为“ Andaman”
您需要在前端对特殊字符进行编码。
即'$' is '%26'
一方面,在您的@RequestParam("cityName")
显式添加名称是一个好习惯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.