QueryDSL介绍

1,QueryDSL仅仅是一个通用的查询框架,专注于通过Java API构建类型安全的SQL查询。

2,Querydsl可以通过一组通用的查询API为用户构建出适合不同类型ORM框架或者是SQL的查询语句,也就是说QueryDSL是基于各种ORM框架以及SQL之上的一个通用的查询框架。

3,借助QueryDSL可以在任何支持的ORM框架或者SQL平台上以一种通用的API方式来构建查询。目前QueryDSL支持的平台包括JPA,JDO,SQL,Java Collections,RDF,Lucene,Hibernate Search。
 

文档说明http://books.aying.org/querydsl_zh_CN/Tutorials/Querying%20JPA.html

参考项目:https://www.jianshu.com/p/99a5ec5c3bd5

官方文档:http://www.querydsl.com/static/querydsl/latest/reference/html/ch02.html

 

QAgency qAgency = QAgency.agency;
List<ShopInfo> pagedOutput = queryFactory.select(Q).distinct().from(Q)
        .innerJoin(qAgency).on(Q.id.eq(qAgency.shopId))
        .where(PredicateBuilder.conjunction()
                .ifHasTextThenAnd(shopName, () -> Q.shopName.like("%" + shopName + "%"))
                .ifHasTextThenAnd(shopHead, () -> Q.manageName.eq(shopHead))
                .ifHasTextThenAnd(channelManagerId, () -> Q.channelManagerId.eq(channelManagerId))
                .ifHasTextThenAnd(province, () -> Q.provinceId.eq(province))
                .ifHasTextThenAnd(city, () -> Q.cityId.eq(city))
                .ifHasTextThenAnd(area, () -> Q.areaId.eq(area))
                .ifHasTextThenAnd(shopStatus, () -> Q.shopStatus.eq(shopStatus))
                .ifHasTextThenAnd(isBranch, () -> Q.isBranch.eq(isBranch))
                .ifHasTextThenAnd(parentId, () -> qAgency.parentShopId.eq(Long.valueOf(parentId)))
                .and(() -> qAgency.agentLevel.eq(agentLevel2))
                .ifNotNullThenAnd(AgencyShopType.CHANNEL_DEALER.getCode(), () -> qAgency.shopType.eq(1))
                .ifTrueThenAnd(staDate != null && !"".equals(staDate) && endDate != null && !"".equals(endDate)
                        , ()   -> Q.createTime.between(staDate, endDate)).get()).offset((pageNo-1)*pageSize).li
mit(pageSize).orderBy(Q.lastUpdateTime.desc()).fetch();

修改语句:

int result = repository.updateByWhere(Q.id.eq(taskId), it ->
        it.set(Q.taskStatus, status)
                .set(Q.lastUpdateBy, UserSession.getUserId(request))
                .set(Q.lastUpdateTime, nowData));
 //findAll排序
List<RollinInventoryModel> rollinInventoryModels = repository.findAll(Q.productId.eq(productId).and(Q.isDelete.eq(false))               .and(Q.inventoryType.eq(RollinInventoryEnums.InventoryType.PROCUREMENT.getCode())),new Sort(Sort.Direction.DESC, "lastUpdateTime"));

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值