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

推荐订阅源

W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Security @ Cisco Blogs
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
F
Full Disclosure
博客园 - 【当耐特】
C
CERT Recently Published Vulnerability Notes
Engineering at Meta
Engineering at Meta
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Threatpost
I
Intezer
V2EX - 技术
V2EX - 技术
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
小众软件
小众软件
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
N
News | PayPal Newsroom
MyScale Blog
MyScale Blog
AI
AI
Vercel News
Vercel News
Spread Privacy
Spread Privacy
美团技术团队
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
V
Vulnerabilities – Threatpost
Schneier on Security
Schneier on Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
Help Net Security
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
L
LINUX DO - 热门话题
U
Unit 42
L
LangChain Blog
Recent Announcements
Recent Announcements

博客园 - 大山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