问题描述
- Spring data jpa 如何进行分页联表查询?
-
具体使用jpa方法:Page findAll(Specification spec, Pageable pageable);
查询语句:select
t.vehicle_id,t.id_number,t.org_code,t.vehicleStatus,t4.TYPE_NAME,t1.TERMINAL_ID,t2.TTYPE_NAME,T3.SIM_NUM
from V_VEHICLEINFO t
left join T_TERMINALINFO t1 on t1.TERMINAL_ID=t.TERMINAL_ID
left join T_TERMINALTYPE t2 on T2.TTYPE_ID=t1.TTYPE_ID
left join T_SIMINFO t3 on t3.SIM_ID=t1.SIM_ID
left join v_vehicletype t4 on T4.TYPE_ID=t.TYPE_ID;
解决方案
public Page<BusinessInfo> getListByPager(final String sSearch,int iDisplayStart,
int iDisplayLength,int iSortCol_0,String sSortDir_0){
Pageable pagerequest = buildPageRequest(iDisplayStart, iDisplayLength, iSortCol_0, sSortDir_0);
Page<BusinessInfo> page = businessInfoDao.findAll(new Specification<BusinessInfo>(){
@Override
public Predicate toPredicate(Root<BusinessInfo> root,CriteriaQuery<?> query, CriteriaBuilder cb) {
//左连接
//root.join(root.getModel().getSingularAttribute("sysUsersX",SysUsersX.class),JoinType.LEFT);
Predicate likeP1 = cb.like(root.get("name").as(String.class),"%"+sSearch+"%");
//Predicate likeP2 = cb.like(depJoin.get("businessNumber").as(String.class), "%"+sSearch+"%");
Predicate likeP2 = cb.like(root.get("businessNumber").as(String.class), "%"+sSearch+"%");
Predicate orP = cb.or(likeP1,likeP2);
//参考: http://www.iteye.com/problems/92130
return cb.and(cb.conjunction(),orP);
}
},pagerequest);
//pagerequest = page.nextPageable();
return page;
}
时间: 2024-12-29 07:14:56