Java 在Spring的GetMapping中使用params会导致多个参数的处理程序方法不明确

Java 在Spring的GetMapping中使用params会导致多个参数的处理程序方法不明确,java,spring,spring-boot,rest,spring-restcontroller,Java,Spring,Spring Boot,Rest,Spring Restcontroller,我在SpringBoot中有以下REST端点 @GetMapping(value = "students", params = {"name"}) public ResponseEntity<?> getByName(@RequestParam final String name) { return new ResponseEntity<>(true, HttpStatus.OK); } @GetMapping(value

我在SpringBoot中有以下REST端点

@GetMapping(value = "students", params = {"name"})
public ResponseEntity<?> getByName(@RequestParam final String name) {
    return new ResponseEntity<>(true, HttpStatus.OK);
}

@GetMapping(value = "students", params = {"tag"})
public ResponseEntity<?> getByTag(@RequestParam final String tag) {
    return new ResponseEntity<>(true, HttpStatus.OK);
}
@GetMapping(value=“students”,params={“name”})
公共响应性getByName(@RequestParam最终字符串名){
返回新的ResponseEntity(true,HttpStatus.OK);
}
@GetMapping(value=“students”,params={“tag”})
公共响应性getByTag(@RequestParam final字符串标记){
返回新的ResponseEntity(true,HttpStatus.OK);
}
对于以下请求,上述处理程序可以正常工作:

localhost:8080/test/students?name=“Aron”

localhost:8080/test/students?tag=“player”

但是,每当我尝试以下操作时:

localhost:8060/test/students?name=“Aron”&tag=“player”

它抛出
java.lang.IllegalStateException:映射的不明确处理程序方法
,并以
HTTP500

我怎样才能改变这种行为?我希望我的应用程序仅在我获得
标记
查询参数或
名称
查询参数时响应。 对于其他任何内容,我希望它忽略,即使它是两个参数的组合


为什么会在这里抛出不明确的错误?我们如何处理它?

您可以使用
@RequestParam(required=false)

@GetMapping(value=“students”)
公众的反应(
@RequestParam(必需=false)最终字符串名称,
@RequestParam(必需=false)最终字符串标记){
if((name==null)==(tag==null)){
返回新的ResponseEntity(false,HttpStatus.BAD_请求);
}
返回新的ResponseEntity(true,HttpStatus.OK);
}

为什么不使用多重方法呢。使用一个方法将name和tag都作为requestparam,然后您就可以处理这种情况