【发布时间】:2020-07-31 18:44:45
【问题描述】:
我有一个 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;
}
}
在我的服务业务逻辑中,如果getFilteredChildren 中的某些参数没有发送应该没问题,但是当我发送请求时遇到问题
http://localhost:8080/api/children?age=10&parentId=3
它由getChildrenByParent 处理,而不是由getFilteredChildren 处理
除了发送所有参数,我还能做什么
http://localhost:8080/api/children?age=10&parentId=3&fullName=
或更改某些端点的路径
【问题讨论】:
标签: java spring spring-boot rest spring-restcontroller