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
QAgency qAgency = QAgency.agency;
List 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 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"));