我需要处理类似的请求
www.example.com/student/thisisname?age=23&country=UK&city=London
我只对 thisisname
部分和 city
参数的值感兴趣。
我有以下RequestMapping,但它不起作用。我也尝试过{name}{.*:city}
。
@RequestMapping(value = "/{name:.*}{city}", method = RequestMethod.GET)
最佳答案
您可以通过两种方式做到这一点。使用@RequestParam或@PathVariable
- By Using @RequestParam
@RequestMapping(value = "/name", method = RequestMethod.GET)
public void someMethod(@RequestParam String city){}
- By using @PathVariable
@RequestMapping(value = "/name/{city}", method = RequestMethod.GET)
public void someMethod(@PathVariable String city){}
您可以使用任何一种方法,只需专注于 URL
关于java - 无法通过 requestMapping 处理请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31283456/