我有一个将可分页作为参数的休息控制器
@GetMapping(value = "/user", produces = APPLICATION_JSON_VALUE,
consumes = APPLICATION_JSON_VALUE)
public BaseResponse getUsers(
Pageable pageRequest) {
System.out.println(pageRequest);
);
}
现在,如果我点击 url http://localhost:8080/user?page=1&size=20&sort=userId 我可以看到 syso 打印为:Page request [number: 1, size 20, sort: userId: ASC]
但是如果我更改控制器方法并根据需要进行分页 = false
@RequestParam(required= false)Pageable pageRequest
如果这次我点击相同的 url,我的 syso 将打印null。我想根据需要制作可分页对象。如何实现
基本上我的要求是用户是否触发如下所示的 url
http://localhost:8080/user?page=1&size=20&sort=userId
当我打印我的 Pageable 对象时,它应该打印 Page request [number: 1, size 20, sort: userId: ASC]
但是如果我像这样 http://localhost:8080/user 触发我的网址,那么我的可分页对象应该打印为 null 而不是一些默认值