2 it90ceo it90ceo 于 2014.04.02 15:58 提问

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个回答

mj19910923
mj19910923   2014.08.29 15:50
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
ly13051057864 请问这联表查询的实体类需要注解吗?如果需要都是怎么注解的
10 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!