Spring Data Jpa分页显示
程序员文章站
2022-04-25 11:16:49
...
/**
* 分页查询电影动态信息
* @param page
* @param pageSize
* @return
*/
@Override
public List<WebSiteInfo> list(WebSiteInfo webSiteInfo, Integer page, Integer pageSize) {
Pageable pageable=new PageRequest(page, pageSize,Sort.Direction.DESC,"publishDate");
Page<WebSiteInfo> pageWebSite=webSiteInfoRepository.findAll(new Specification<WebSiteInfo>() {
@Override
public Predicate toPredicate(Root<WebSiteInfo> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
Predicate predicate=cb.conjunction();
if(webSiteInfo!=null){
if(StringUtil.isNotEmpty(webSiteInfo.getInfo())){
predicate.getExpressions().add(cb.like(root.get("info"), "%"+webSiteInfo.getInfo().trim()+"%"));
}
}
return predicate;
}
}, pageable);
return pageWebSite.getContent();
}
/**
* 获取总记录数
* @return
*/
@Override
public Long getCount(WebSiteInfo webSiteInfo) {
Long count=webSiteInfoRepository.count(new Specification<WebSiteInfo>() {
@Override
public Predicate toPredicate(Root<WebSiteInfo> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
Predicate predicate=cb.conjunction();
if(webSiteInfo!=null){
if(StringUtil.isNotEmpty(webSiteInfo.getInfo())){
predicate.getExpressions().add(cb.like(root.get("info"), "%"+webSiteInfo.getInfo().trim()+"%"));
}
}
return predicate;
}
});
return count;
}
上一篇: 2020-08-25
下一篇: 解决ie6下最小高度问题
推荐阅读
-
Spring Data JPA实践与学习
-
荐 一篇文章带你快速入门 Spring Data JPA
-
Spring Data Jpa 中级联操作CascadeType的含义
-
Spring Data Jpa+SpringMVC+Jquery.pagination.js实现分页示例
-
springboot使用spring-data-jpa操作MySQL数据库
-
Spring Data JPA 实现多表关联查询的示例代码
-
Spring Data JPA+kkpager实现分页功能实例
-
EasyUi+Spring Data 实现按条件分页查询的实例代码
-
Spring Data Jpa+SpringMVC+Jquery.pagination.js实现分页示例
-
Spring Data JPA+kkpager实现分页功能实例