In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "how to write MybatisPlus to achieve paging query and dynamic SQL query", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn "how to write MybatisPlus to achieve paging query and dynamic SQL query"!
Catalogue
I. description
Second, the mode of realization
III. Summary
I. description
Implement the function in the following figure and analyze it. There are paging queries and dynamic queries based on plan status, start time, and company name.
Second, the mode of realization
Controller layer
/ * @ param userId Commissioner's id * @ param planState Plan status * @ param planStartTime Plan start time * @ param emtCode Company name-split id * @ return java.util.List * @ Author zhaoxiaodong * @ Description Advanced query-based on plan status, schedule, Company name query * @ Date 9:04 2021-9-29 * / @ PostMapping ("/ selectPlanByStateTimeCompany") public Page selectPlanByStateTimeCompany (@ RequestParam (required = false) DefaultValue = "1") int limit, @ RequestParam (required = false,defaultValue = "1") int page, @ RequestParam (required = true) Long userId,@RequestParam (required = false,defaultValue = "0") int planState,@RequestParam (required = false) String planStartTime,@RequestParam (required = false) Long emtCode) {/ / get all plans under the commissioner whose status is not started List myPlanList = crmCustomerPlanService.selectNoStartPlan (userId) If (StringUtil.isNotEmpty (planStartTime)) {/ / determine the start time and current time of the plan DateTimeFormatter dtf = DateTimeFormatter.ofPattern ("yyyy-MM-dd HH:mm:ss"); LocalDateTime planTime = LocalDateTime.parse (planStartTime, dtf); / / store overdue plan List overDuePlan = new ArrayList () For (CrmCustomerPlan customerPlan: myPlanList) {if (LocalDateTime.now (). IsAfter (planTime)) {/ / the current time is after the planned time, indicating that the planned time has elapsed. At this time, we need to change its status to overdue customerPlan.setPlanState (PlanStateEnum.OVERDUE.getCode ()); overDuePlan.add (customerPlan). }} if (overDuePlan.size () > 0) {/ / after traversal, we can make changes to the data crmCustomerPlanService.updateBatchById (overDuePlan);}} / / the next step is to query the data return crmCustomerPlanService.selectPlanByStateTimeCompany (limit,page,userId, planState, planStartTime, emtCode) }
There are limit and page in Controller. The limit of limit per page and the number of pages of page
Service layer
/ * @ param userId * @ return java.util.List * @ Author zhaoxiaodong * @ Description Advanced query-query by plan status, time, company name * @ Date 9:06 2021-9-29 * / @ Override public Page selectPlanByStateTimeCompany (int limit,int page,Long userId, int planState, String planStartTime, Long emtCode) {Page pagelimit= new Page (page,limit); QueryWrapper crmCustomerPlanQueryWrapper = new QueryWrapper () CrmCustomerPlanQueryWrapper.eq ("create_user_id", userId); if (planStatekeeper 0) {crmCustomerPlanQueryWrapper.eq ("plan_state", planState);} if (StringUtil.isNotEmpty (planStartTime)) {crmCustomerPlanQueryWrapper.eq ("plan_start_time", planStartTime);} if (StringUtil.isNotEmpty (String.valueOf (emtCode) {crmCustomerPlanQueryWrapper.eq ("emt_code", emtCode) } return crmCustomerPlanMapper.selectPage (pagelimit,crmCustomerPlanQueryWrapper);}
In the Service layer, dynamic SQL queries can be implemented through if and QueryWrapper.
Paging, using the Page object, must be Mybatis. Then call selectPage to pass in the object and query conditions.
III. Summary
MybatisPlus is really easy to use, saving us a lot of SQL statements and configuration information.
Paging configuration information for Mybatis
/ * New paging plug-in * / @ Bean public MybatisPlusInterceptor mybatisPlusInterceptor () {MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor (); mybatisPlusInterceptor.addInnerInterceptor (new PaginationInnerInterceptor (DbType.MYSQL)); return mybatisPlusInterceptor;} so far, I believe you have a deeper understanding of "how to write MybatisPlus to achieve paging query and dynamic SQL query". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.