У меня есть RestController.
@RestController
@RequestMapping("/api/children")
public class ChildController {
private ChildService childService;
@Autowired
public ChildController(ChildService childService) {
this.childService = childService;
}
@GetMapping
public List<ChildDto> list() {
List<ChildDto> response = childService.list();
return response;
}
@GetMapping(params = "parentId")
public List<ChildDto> getChildrenByParent(@RequestParam Integer parentId) {
List<ChildDto> response = childService.getChildrenByParent(parentId);
return response;
}
@GetMapping(params = {"fullName", "age", "parentId"})
public List<ChildDto> getFilteredChildren(@RequestParam String fullName,
@RequestParam Integer age,
@RequestParam Integer parentId) {
List<ChildDto> response = childService.getFilteredChildren(fullName, age, parentId);
return response;
}
}
В моей служебной логике c в обслуживании все должно быть в порядке, если какой-либо параметр в getFilteredChildren
не отправляется, но у меня возникает проблема, когда я отправляю запрос на
http://localhost:8080/api/children?age=10&parentId=3
обрабатывается getChildrenByParent
, а не getFilteredChildren
Что я могу сделать, кроме отправки всех параметров типа
http://localhost:8080/api/children?age=10&parentId=3&fullName=
или изменение пути для некоторых конечных точек