我正在尝试对我的spring boot应用程序实施过滤和分页,但是遇到了问题。
这是我的控制器:page和size具有默认值,其他所有参数都应是可选的,如下所示。
@PreAuthorize("hasAuthority('service_manager')")
@RequestMapping(path = "/clients", method = RequestMethod.GET)
public Page<ClientResponse> getClients(
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size,
@RequestParam(required = false) String companyName,
@RequestParam(required = false) BigInteger firmRegNo,
@RequestParam(required = false) String address,
@RequestParam(required = false) BigInteger contractNo,
@RequestParam(required = false) BigInteger monthlyPay,
@RequestParam(required = false) User.UserStatus status
) {
ClientListRequest request = new ClientListRequest(companyName, firmRegNo, address, contractNo, monthlyPay, status);
return clientService.getAllClients(request, of(page, size, Sort.Direction.DESC))
.map(ClientResponse::new);
}
向“ http://localhost:8080/clients?companyName=Selver”发出GET请求时,我收到以下响应:
{
"timestamp": "2019-02-18T07:40:44.182+0000",
"status": 500,
"error": "Internal Server Error",
"message": "At least one property must be given!",
"path": "/clients"
}
同样的响应也没有参数。有什么想法吗?
答案 0 :(得分:0)
发现错误:
return clientService.getAllClients(request, of(page, size, Sort.Direction.DESC))
.map(ClientResponse::new);
在Sort.Direction.DESC
之后至少需要一个属性,默认情况下会对其进行排序。我使用了客户端的“ createTime”来使它正常工作!
return clientService.getAllClients(request, of(page, size, Sort.Direction.DESC, "createTime"))
.map(ClientResponse::new);