In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail the example analysis of mybatis multi-table query processing in spring. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
Package com.swhy.bw.advisor.center.comment;import com.github.pagehelper.Page;import com.github.pagehelper.PageHelper;import com.github.pagehelper.PageInfo;import com.swhy.bw.advisor.dal.mapper.ApCommentExtMapper;import com.swhy.bw.advisor.dao.biz.response.theme.AdviserThemeDetailRes;import com.swhy.bw.advisor.dao.biz.response.user.UserInfoRes;import com.swhy.bw.advisor.dao.center.request.comment.CommentCenterListReq;import com.swhy.bw.advisor.dao.center.request.comment.CommentCenterModifyReq Import com.swhy.bw.advisor.dao.center.request.comment.SelectCommentReq;import com.swhy.bw.advisor.dao.center.response.comment.CommentCenterListRes;import com.swhy.bw.advisor.dao.center.response.comment.CommentDetailRes;import com.swhy.bw.advisor.dao.entity.ApComment;import com.swhy.bw.advisor.dao.entity.ApLiveRoom;import com.swhy.bw.advisor.dao.entity.VdInvestAdviser;import com.swhy.bw.advisor.elasticsearch.utils.AdviserEsUtils;import com.swhy.bw.advisor.elasticsearch.utils.AdviserThemeEsUtils Import com.swhy.bw.advisor.elasticsearch.utils.LiveRoomEsUtils;import com.swhy.bw.advisor.elasticsearch.utils.UserEsUtils;import com.swhy.bw.advisor.enums.CommentEnums;import com.swhy.bw.advisor.util.CollectionUtils;import com.swhy.bw.advisor.util.ExceptionUtil;import com.swhy.bw.advisor.util.StringUtils;import com.swhy.bw.advisor.util.date.DateFormat;import com.swhy.bw.advisor.util.date.DateUtils;import com.swhy.bw.advisor.util.exception.BusinessException Import com.swhy.bw.advisor.util.log.LOG_TYPE;import com.swhy.bw.advisor.util.log.LogUtil;import com.swhy.bw.advisor.util.route.RouteUtil;import com.swhy.bw.common.util.date.DateUtil;import org.springframework.beans.BeanUtils;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import java.util.*;import java.util.stream.Collectors;@Servicepublic class ApCommentMgmtService {@ Autowired private ApCommentExtMapper apCommentExtMapper; @ Autowired private AdviserThemeEsUtils adviserThemeEsUtils Public PageInfo findApCommentList (CommentCenterListReq apCommentReq) throws BusinessException {final String METHOD = "findApCommentList"; try {PageHelper.startPage (apCommentReq.getPageNum (), apCommentReq.getPageSize ()); LogUtil.logInput (LOG_TYPE.BIZ.val, this, METHOD, apCommentReq) / / request parameter if (apCommentReq.getEndDate ()! = null) apCommentReq.setEndDate (DateUtil.addDay (apCommentReq.getEndDate (), 1)); / / query comment list Page records = (Page) apCommentExtMapper.selectCommentListAll (apCommentReq); if (records = = null) {return new PageInfo () } Page resPage = new Page (); BeanUtils.copyProperties (records, resPage); / / query customer information HashMap adviserMap = getAdviserInfo (records); / / query title information HashMap titleMap If (apCommentReq.getCommentType (). Equals (CommentEnums.comment_type_theme.getValue () {titleMap = getThemeInfo (records);} else {titleMap = getLiveroomInfo (records);} / / convert records.forEach (record-> {CommentCenterListRes res = new CommentCenterListRes () BeanUtils.copyProperties (record, res); res.setTitle (titleMap.getOrDefault (record.getCommentId (), ")); res.setInvestAdviserName (adviserMap.getOrDefault (record.getAdviserId (),")); res.setPublishTime (DateUtil.formateDate2Str (record.getPublishTime (), "yyyy-MM-dd HH:mm:ss")); res.setCommentContent (record.getContent ()) ResPage.add (res);}); return new PageInfo (resPage);} catch (Exception e) {LogUtil.logError (LOG_TYPE.BIZ.val, this, METHOD, e); throw ExceptionUtil.generateException ("comment list query exception", e);} private HashMap getThemeInfo (Page records) {HashMap themeMap = new HashMap () List themeIds = records.stream (). Map (ApComment::getCommentId). Distinct (). Collect (Collectors.toList ()); List themeDetailResList = adviserThemeEsUtils.findThemeByIds (themeIds); if (CollectionUtils.isNotEmpty (themeDetailResList)) themeDetailResList.forEach (theme-> themeMap.put (theme.getId (), theme.getTitle ()); return themeMap;} private HashMap getLiveroomInfo (Page records) {HashMap themeMap = new HashMap () List liveroomIds = records.stream (). Map (ApComment::getCommentId). Distinct (). Collect (Collectors.toList ()); List liveRooms = LiveRoomEsUtils.findByIds (liveroomIds); if (CollectionUtils.isNotEmpty (liveRooms)) liveRooms.forEach (liveRoom-> themeMap.put (liveRoom.getId (), liveRoom.getTitle ()); return themeMap;} private HashMap getAdviserInfo (Page records) {HashMap adviserMap = new HashMap () List adviserIds = records.stream (). Map (ApComment::getAdviserId). Distinct (). Collect (Collectors.toList ()); List advisers = AdviserEsUtils.findByIds (adviserIds); if (CollectionUtils.isNotEmpty (advisers)) advisers.forEach (adviser-> adviserMap.put (adviser.getId (), adviser.getInvestAdviserName ()); return adviserMap }} this is the end of the article on "sample analysis of mybatis multi-table query processing in spring". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.