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;

1个回答

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;
}
ly13051057864
平平常常打代码 请问这联表查询的实体类需要注解吗?如果需要都是怎么注解的
接近 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问