spring中mybatis多表查询处理的示例分析
发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,这篇文章将为大家详细讲解有关spring中mybatis多表查询处理的示例分析,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。package com.swhy.bw.
千家信息网最后更新 2026年11月01日spring中mybatis多表查询处理的示例分析
这篇文章将为大家详细讲解有关spring中mybatis多表查询处理的示例分析,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
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); // 请求参数 if (apCommentReq.getEndDate() != null) apCommentReq.setEndDate(DateUtil.addDay(apCommentReq.getEndDate(), 1)); // 查询评论列表 Page records = (Page) apCommentExtMapper.selectCommentListAll(apCommentReq); if (records == null) { return new PageInfo<>(); } Page resPage = new Page<>(); BeanUtils.copyProperties(records, resPage); // 查询投顾信息 HashMap adviserMap = getAdviserInfo(records); // 查询标题信息 HashMap titleMap; if (apCommentReq.getCommentType().equals(CommentEnums.comment_type_theme.getValue())) { titleMap = getThemeInfo(records); } else { titleMap = getLiveroomInfo(records); } // 转换 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("评论列表查询异常", 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; }}关于"spring中mybatis多表查询处理的示例分析"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
查询
篇文章
示例
分析
处理
信息
更多
评论
不错
实用
内容
参数
文章
标题
知识
参考
帮助
有关
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
互联网科技图片
中关村互联网科技集团
深圳科技互联网
艾特科技互联网
广州互联网络科技有限公司
苏州互联网科技贷款公司
万达互联网科技
撒么互联网科技公司
互联网金融科技公司干啥的
互联网科技项目计划书材料类
互联网与医疗科技
互联网科技人工智能实验室
广州千川互联网科技有限公司
中天科技中国工业互联网
银川新华互联网科技学校原画
互联网时代高科技布局
广州三三互联网科技有限公司
杭州科技互联网公司有哪些
承德科技产业互联网平台
科技互联网企业在行动
云南咖啡
华宇互联网科技
丰台科技园 互联网
互联网科技公司的市场部门
深圳国际航运科技和互联网
互联网科技教育视频
江阴互联网智能科技产品进口
迪庆互联网科技招生
容联科技互联网电商
科技互联网专业务虚会材料