![](/img/trans.png)
[英]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.