我有一些Sprint控制器映射,如下所示。
@GetMapping("/hello/{name}/age")
private String hello(@PathVariable(value = "name", required = true) String name){
//...
}
@GetMapping("/hello/{name}")
private String hello(@PathVariable(value = "name", required = true) String name){
//...
}
@GetMapping("/name")
private ResponseEntity<?> queryPerson(@RequestParam(value = "query", required = false) String query) {
// ...
}
但是有客户竞争来处理以下情况
当客户端发送/ hello / john / age时,我应该返回与年龄相关的pojo,但是当客户端调用/ hello // age时,我必须返回400,其中包含无效的用户名作为错误。
因为我的代码已经存在其他映射hello / {name},所以它正在调用此API并尝试查找username ='age'并重现404。
在这里,当用户调用/ hello // age时,我被假定为400,那么在春季如何处理呢?
Tomcat正在折叠双斜杠:
http://mail-archives.apache.org/mod_mbox/tomcat-users/201912.mbox/%[email protected]%3E