惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Engineering at Meta
Engineering at Meta
博客园_首页
H
Help Net Security
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
B
Blog
I
InfoQ
SecWiki News
SecWiki News
T
Tailwind CSS Blog
Spread Privacy
Spread Privacy
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
N
Netflix TechBlog - Medium
P
Palo Alto Networks Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Vercel News
Vercel News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
Kaspersky official blog
M
MIT News - Artificial intelligence
S
Schneier on Security
T
Threat Research - Cisco Blogs
F
Fortinet All Blogs
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
The Cloudflare Blog
Recent Announcements
Recent Announcements
Security Latest
Security Latest
G
GRAHAM CLULEY
IT之家
IT之家
Y
Y Combinator Blog
The Last Watchdog
The Last Watchdog
腾讯CDC
Google DeepMind News
Google DeepMind News
V
V2EX
S
Securelist
TaoSecurity Blog
TaoSecurity Blog
B
Blog RSS Feed
S
SegmentFault 最新的问题
博客园 - 叶小钗
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
Project Zero
Project Zero
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
F
Full Disclosure

博客园 - 大山008

若依导出excel时decimal数据千分位格式化 SpringBoot如何引入deepseek-多轮对话 EasyExcel实现百万级数据导入导出 SpringAMQP整合RabbitMQ使用 win11安装redis步骤详解 ftp与sftp工具类 stream流的一些常用用法 子类的toString方法如何打印父类的属性 MySQL常见的几种优化方案 关于若依AsyncFactory的一些思考,记录一下 Vue 路由跳转、路由传参、跳转区别、传值取值 MYSQL中substring_index()用法 mybatis sql 解决 in 参数过多的问题 MySQL之json数据操作 validate校验,记录一种思路 在vue中用multipart/form-data方式上传文件并同表单同步提交数据 Java微信转发及网络检测 生成带有二维码的海报 java将指定文件夹下面的所有图片压缩到指定大小以内并保存图片 Lock与ReentrantLock、Synchronized
mybatis查询返回map键值对的问题
大山008 · 2023-04-21 · via 博客园 - 大山008

业务场景:部门表数据批量导入,每条数据需要查表获取parentId,ancestors并赋值

目标:一次查出,键(部门名称)值(部门信息)已确认:部门名称不存在重复得情况

1、sql

<resultMap id="result" type="com.zhhs.project.system.vo.BeanVo">
    <result column="dept_id" property="id"/>
    <result column="dept_name" property="name"/>
    <result column="ancestors" property="ancestors"/>
</resultMap>

<select id="selectDepts" resultMap="result">
    select dept_id, dept_name,ancestors
    from sys_dept where del_flag = '0' and status = '0'
</select>

2、定义key

/**
     * 返回部门键值对:键为部门名称
     * @return
     */
    @MapKey("name")
    Map<String, BeanVo> selectDepts();

3、对象

@Data
public class BeanVo {
    private Long id;
    private String name;
    private String ancestors;
}

4、使用:代码片段

for (DeptTemplate deptTemplate : deptList){
SysDept dept = new SysDept(); BeanUtils.copyProperties(deptTemplate,dept); dept.setParentId(deptMap.get(deptTemplate.getParentName()).getId()); dept.setAncestors(deptMap.get(deptTemplate.getParentName()).getAncestors() + ","+ deptMap.get(deptTemplate.getParentName()).getId());}
-----------
}

参考:https://blog.csdn.net/gongdileidechouzhu/article/details/121478926