Spring启动控制器URL验证
我有一些Sprint控制器映射,如下所示Spring启动控制器URL验证,spring,spring-boot,spring-restcontroller,Spring,Spring Boot,Spring Restcontroller,我有一些Sprint控制器映射,如下所示 @GetMapping("/hello/{name}/age") private String hello(@PathVariable(value = "name", required = true) String name){ //... } @GetMapping("/hello/{name}") private String hello(@PathVariable(value = "name", re
@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) {
// ...
}
@GetMapping(“/hello/{name}/age”)
私有字符串hello(@PathVariable(value=“name”,required=true)字符串名){
//...
}
@GetMapping(“/hello/{name}”)
私有字符串hello(@PathVariable(value=“name”,required=true)字符串名){
//...
}
@GetMapping(“/name”)
private ResponseEntity queryPerson(@RequestParam(value=“query”,required=false)字符串查询){
// ...
}
但有一个客户体验来处理以下情况
当客户端发送/hello/john/age时,我应该返回与年龄相关的pojo,但当客户端调用/hello//age时,我必须返回400,用户名无效作为错误
由于我的代码是im,我已经有了其他映射hello/{name},所以它正在调用这个API并试图找到username='age',然后重试404
在这里,当用户调用/hello//age时,我可以使用400,那么如何在春季处理这个问题呢 将没有机会创建400 Tomcat正在折叠双斜杠: