JpaRepository 接口中的分页方法 findAll(pageable) 查询无结果集 求指点!!!!!!!!!!!!
答案:2 悬赏:0 手机版
解决时间 2021-04-04 04:17
- 提问者网友:
- 2021-04-03 18:34
JpaRepository 接口中的分页方法 findAll(pageable) 查询无结果集 求指点!!!!!!!!!!!!
最佳答案
- 五星知识达人网友:低血压的长颈鹿
- 2021-04-03 18:43
public Page getUserTask(Long userId, Map searchParams, int pageNumber, int pageSize,
String sortType) {
PageRequest pageRequest = buildPageRequest(pageNumber, pageSize, sortType);
Specification spec = buildSpecification(userId, searchParams);
return taskDao.findAll(spec, pageRequest);
}
private PageRequest buildPageRequest(int pageNumber, int pagzSize, String sortType) {
Sort sort = null;
if ("auto".equals(sortType)) {
sort = new Sort(Direction.DESC, "id");
} else if ("title".equals(sortType)) {
sort = new Sort(Direction.ASC, "title");
}
return new PageRequest(pageNumber - 1, pagzSize, sort);
}
private Specification buildSpecification(Long userId, Map searchParams) {
Map filters = SearchFilter.parse(searchParams);
filters.put("user.id", new SearchFilter("user.id", Operator.EQ, userId));
Specification spec = DynamicSpecifications.bySearchFilter(filters.values(), Task.class);
return spec;
}
String sortType) {
PageRequest pageRequest = buildPageRequest(pageNumber, pageSize, sortType);
Specification
return taskDao.findAll(spec, pageRequest);
}
private PageRequest buildPageRequest(int pageNumber, int pagzSize, String sortType) {
Sort sort = null;
if ("auto".equals(sortType)) {
sort = new Sort(Direction.DESC, "id");
} else if ("title".equals(sortType)) {
sort = new Sort(Direction.ASC, "title");
}
return new PageRequest(pageNumber - 1, pagzSize, sort);
}
private Specification
Map
filters.put("user.id", new SearchFilter("user.id", Operator.EQ, userId));
Specification
return spec;
}
全部回答
- 1楼网友:痴妹与他
- 2021-04-03 19:48
pageable的page是从0开始的
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯