使用QueryDSL补充springDataJpa进行复杂动态sql语句进行sql查询 实现 关联 分页等功能

本秂侑毒 提交于 2020-01-13 14:47:29
@Test
public void testComplexSelect() {
    QQyOnlineCall onlineCall = QQyOnlineCall.qyOnlineCall;
    QClientList clientList = QClientList.clientList;
    // page必须从1开始
    PageRequest request = PageRequest.of(0, 10);
    // 构建复杂查询语句
    List<Tuple> result = mFactory.select(onlineCall.id, onlineCall.cUsesign, onlineCall.cYgscode, clientList.cClientname, clientList.cPhone1)
            .from(onlineCall)
            .leftJoin(clientList)
            .on(onlineCall.cClientid.eq(clientList.id))
            .where(onlineCall.cCom.eq("C0003"))
            .limit(request.getPageSize()) // 单页查询数量
            .offset(request.getPageSize() * request.getPageNumber()) // 偏移量
            .fetch();
    // 获取结果
    for (Tuple tuple : result) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("id", tuple.get(onlineCall.id));
        map.put("useSign", tuple.get(onlineCall.cUsesign));
        map.put("ygsCode", tuple.get(onlineCall.cYgscode));
        map.put("clientName", tuple.get(clientList.cClientname));
        map.put("phone", tuple.get(clientList.cPhone1));
        System.out.println(JsonUtils.toJson(map));
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!