In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "lambdaQueryWrapper multi-conditional nested query method is what", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "lambdaQueryWrapper multi-conditional nested query method is what" it!
LambdaQueryWrapper multi-conditional nested query
Requirements: obtain data stored by year and week over a period of time according to conditions
The table structure is as follows: userNetTypemoduleNamecityNamesubjectCnamesubjectEnamepvuvyearweek11 Jiangsu Province Reaper theme sszt1007020195111 Jiangsu Province Sea Thief King theme hzwzt2008020195211 Jiangsu Province Naruto theme hyrzzt30090202001/** * @ param pageNum current page * @ param pageSize number of param moduleName products * @ param userNetType operator * @ param cityName city name * @ param beginTime any day of the beginning week (example For example: 2019-12-20) * @ param endTime any day of the end week (for example: 2020-01-20) * @ param keyWord query conditions (English or Chinese name of the topic) * @ return * / / start year String beginYear = null / / end year String endYear = null; / / start weeks String beginWeek = null; / / end weeks String endWeek = null / * this part is ignored and other methods are called. Anyway, the purpose is to get the year in which the start date is located, the number of weeks and the number of weeks * / if (StringUtils.isBlank (beginTime) | | StringUtils.isBlank (endTime)) {DateTime dateTime = DateUtil.lastWeek () / format date, result: yyyyMMdd beginTime = DateUtil.formatDate (dateTime); beginYear = TimeUtils.getDateOfYearWeek (beginTime) .get ("year"); endYear = beginYear; beginWeek = TimeUtils.getDateOfYearWeek (beginTime) .get ("week"); endWeek = beginWeek;} else {beginYear = TimeUtils.getDateOfYearWeek (beginTime) .get ("year") EndYear = TimeUtils.getDateOfYearWeek (endTime) .get ("year"); beginWeek = TimeUtils.getDateOfYearWeek (beginTime) .get ("week"); endWeek = TimeUtils.getDateOfYearWeek (endTime) .get ("week");} Page page = new Page (pageNum, pageSize); LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery (); if (beginYear.equals (endYear)) {queryWrapper.eq (DwSubjectDataInfoWw::getYear, beginYear) QueryWrapper.between (DwSubjectDataInfoWw::getWeek, beginWeek, endWeek);} else {/ / because of the final variable problem in the Java8 Lambda expression, reassign a parameter to solve String year1 = beginYear; String year2 = endYear; String week1 = beginWeek; String week2 = endWeek QueryWrapper.and (wrapper-> wrapper.and (wrapper1-> wrapper1.eq (DwSubjectDataInfoWw::getYear, year1) .ge (DwSubjectDataInfoWw::getWeek, week1)) .or (wrapper2-> wrapper2.eq (DwSubjectDataInfoWw::getYear, year2) .le (DwSubjectDataInfoWw::getWeek, week2));} queryWrapper.orderByDesc (DwSubjectDataInfoWw::getYear); queryWrapper.orderByDesc (DwSubjectDataInfoWw::getWeek) If (StrUtil.isNotEmpty (cityName)) {queryWrapper.eq (DwSubjectDataInfoWw::getCityName, cityName);} if (StrUtil.isNotEmpty (userNetType)) {queryWrapper.eq (DwSubjectDataInfoWw::getUserNetType, userNetType);} if (StrUtil.isNotEmpty (moduleName)) {queryWrapper.eq (DwSubjectDataInfoWw::getModuleName, moduleName) } / / the search criteria can be if (StrUtil.isNotEmpty (keyWord)) {queryWrapper.and (wrapper-> wrapper.like (DwSubjectDataInfoWw::getSubjectCname, keyWord). Or (). Like (DwSubjectDataInfoWw::getSubjectEname, keyWord));} try {Page list = dwSubjectDataInfoWwService.page (page, queryWrapper); return AjaxResult.success (list) } catch (Exception e) {logger.error ("error getting weekly thematic data list, error message:", e); return AjaxResult.error ();} the following is the SQL statement WHERE (year =?) generated according to the condition. AND week > =?) OR (year =? AND week
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.