Java 在Spring Boot RestController中区分带查询参数的端点和不带查询参数的端点

Java 在Spring Boot RestController中区分带查询参数的端点和不带查询参数的端点,java,spring,spring-boot,Java,Spring,Spring Boot,在rest控制器中,如何区分具有查询参数的端点和不具有查询参数的端点?下面的映射抛出此错误- 原因:java.lang.IllegalStateException:映射不明确。不能 映射“itemController”方法 @GetMapping(“/”) @ResponseStatus(HttpStatus.OK) 公共列表getAllItems(){ 返回menuService.getAllItems(); } @GetMapping(“/”) @ResponseStatus(HttpSta

在rest控制器中,如何区分具有查询参数的端点和不具有查询参数的端点?下面的映射抛出此错误-

原因:java.lang.IllegalStateException:映射不明确。不能 映射“itemController”方法

@GetMapping(“/”)
@ResponseStatus(HttpStatus.OK)
公共列表getAllItems(){
返回menuService.getAllItems();
}
@GetMapping(“/”)
@ResponseStatus(HttpStatus.OK)
公共列表getAllItems(@RequestParam(“itemtype”)itemtype itemtype){
返回menuService.findItemsByItemType(itemType);
}

将参数设置为可选:

@GetMapping(“/”)
@ResponseStatus(HttpStatus.OK)
公共列表getAllItems(@RequestParam(name=“itemtype”,required=false)itemtype itemtype){
if(itemType==null)
返回menuService.getAllItems();
返回menuService.findItemsByItemType(itemType);
}
@GetMapping("/")
@ResponseStatus(HttpStatus.OK)
public List<Item> getAllItems(){
    return menuService.getAllItems();
}


@GetMapping("/")
@ResponseStatus(HttpStatus.OK)
public List<Item> getAllItems(@RequestParam("itemtype") ItemType itemType){
    return menuService.findItemsByItemType(itemType);
}