无法通过 requestMapping 处理请求

Cannot handle request by requestMapping

我需要处理像

这样的请求
www.example.com/student/thisisname?age=23&country=UK&city=London

我只对 city 参数的 thisisname 部分和值感兴趣。

我有以下 RequestMapping,但它不起作用。我也试过了{name}{.*:city}

@RequestMapping(value = "/{name:.*}{city}", method = RequestMethod.GET)

您可以通过两种方式完成。使用 @RequestParam 或 @PathVariable

  1. By Using @RequestParam
@RequestMapping(value = "/name", method = RequestMethod.GET)
public void someMethod(@RequestParam String city){}
  1. By using @PathVariable
@RequestMapping(value = "/name/{city}", method = RequestMethod.GET)
public void someMethod(@PathVariable String city){}

您可以使用任何一种方法,只需要专注于 URL

您可以使用 PathVariable 和 RequestParam 注释来处理它。在下面的代码名称是 thisisname 部分,城市是查询参数城市值。

@RequestMapping(value = "/student/{name}", method = RequestMethod.GET)
public void someMethod(@PathVariable String name, @RequestParam("city") String city){

}