In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to use Spring Data JPA QueryDsl query and paging, I hope you will learn something after reading this article, let's discuss it together!
Spring Data JPA uses QueryDsl to query and page QProblemPoint qProblemPoint = QProblemPoint.problemPoint; Map map = getWhere (param) JPAQuery query = jpaQueryFactory .selectFrom (qProblemPoint) .where (qProblemPoint.problemClassify.like (map.get ("problemClassify")), / / question classification qProblemPoint.problemLevel.like (map.get ("problemLevel")), / / question level qProblemPoint.securityRiskEvent.like (map.get ("securityRiskEvent")) / / risk event qProblemPoint.riskItems.like (map.get ("riskItems")) / / Security risk item) List list = query .offset (param.getStart ()) .limit (param.getLength ()) .fetch (); long count = query.fetchCount ()
QProblemPoint: is a compiled entity
Query: a collection queried by criteria
List: paging according to the information from the front desk
.fetch (): equivalent to .get (), you can see the return type.
Use QueryDSL
Supplement springDataJpa to carry out complex dynamic sql statements and sql query to realize associated paging and other functions
@ Testpublic void testComplexSelect () {QQyOnlineCall onlineCall = QQyOnlineCall.qyOnlineCall; QClientList clientList = QClientList.clientList; / / page must start at 1 PageRequest request = PageRequest.of (0,10) / / build complex query statements List 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 ()) / / number of single-page queries. Offset (request.getPageSize () * request.getPageNumber ()) / offset .fetch () / / get the result for (Tuple tuple: result) {HashMap 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));}} after reading this article, I believe you have some understanding of "how Spring Data JPA uses QueryDsl to query and page". If you want to know more about it, welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.