我正在尝试只获取请求参数名称:
RequestMapping("/test?{state}",method=RequestMethod.GET)
public String test(@PathVariable state){
// if I hit test?CA - state is coming as "est"
}
我应该如何获得州? 我不想做url / test?state = CA
答案 0 :(得分:1)
您正在混合路径变量和网址参数。
这应该有效:
GET /test/CA
->
@RequestMapping(value = "/test/{state}", method = GET)
public String test(@PathVariable String state){
// ...
}
就像这样:
GET /test?CA
->
@RequestMapping(value = "/test", method = GET)
public String test(@RequestParam Map<String, String> parameters){
if (parameters.containsKey("CA")) {
// ...
}
}
就像这样:
GET /test?state=CA
->
@RequestMapping(value = "/test", method = GET)
public String test(@RequestParam String state){
// ...
}