当前位置:网站首页>@Mapkey usage instructions
@Mapkey usage instructions
2022-07-24 23:50:00 【Patients with intermittent sadness】
One 、 Preface
@MapKey yes MyBatis Comments on the framework , Role is to List The result set is converted to key-value Formal Map Result set , It is convenient to quickly query the specified results from the result set .

1.1、 usage
1.1.1、dao layer
@MapKey("id")
Map getStudents();
1.1.2、xml layer
<!-- Get basic information of students -->
<select id="getStudents" resultType="map">
SELECT id, idCard, name FROM students
</select>1.2、 effect
Before using

After using

Two 、 matters needing attention
2.1、 Be careful key The type of
It is worth noting that , adopt @MapKey The comment returns Map, Its key The type of is consistent with the specified field type .
for example : Appoint id As Map Of key,id by int type , Then the Map Of key Also for the integer type , If you pass String Type of key To get value, You can't get .

2.2 、 Solution
2.2.1、 Keep it as it is.
If you don't need to use it externally , You can keep it as it is , Just pay attention key The type of .
2.2.2、 Unified use String As Key
Directly through mysql function , Modify the returned data type .
<!-- Get basic information of students -->
<select id="getStudents" resultType="map">
SELECT Cast(id as char) AS id, idCard, name FROM students
</select>3、 ... and 、 Reference article
@MapKey Use _make_888 The blog of -CSDN Blog [email protected]
边栏推荐
- Answers to some problems encountered in the process of Xperia XZ (f8332) brushing and root
- 云计算三类巨头:IaaS、PaaS、SaaS,分别是什么意思,应用场景是什么?
- 指针与数组
- QT | event system qevent
- Implementation of cat and dog data set classification experiment based on tensorflow and keras convolutional neural network
- Be an artistic test / development programmer and slowly change yourself
- Which securities account is the best and safest for beginners
- cloud chart
- Notes of Teacher Li Hongyi's 2020 in-depth learning series 3
- Multithreading & high concurrency (the latest in the whole network: interview questions + map + Notes) the interviewer is calm
猜你喜欢

给生活加点惊喜,做创意生活的原型设计师丨编程挑战赛 x 选手分享

Heap sort summary

How to propose effective solutions for high-end products? (1 methodology + 2 cases + 1 List)

Power consumption of chip

2022 the most NB JVM foundation to tuning notes, thoroughly understand Alibaba P6 small case

ShardingSphere-数据库分库分表简介

Notes of Teacher Li Hongyi's 2020 in-depth learning series 2

The new version of SSM video tutorial in shangsilicon valley was released

痞子衡嵌入式:MCUXpresso IDE下将源码制作成Lib库方法及其与IAR,MDK差异

C language program environment and preprocessing
随机推荐
First experience of flask
Notes of Teacher Li Hongyi's 2020 in-depth learning series 3
基于TensorFlow和Keras的卷积神经网络实现猫狗数据集分类实验
Install Kaspersky 2018 under win server 2012 R2
Answers to some problems encountered in the process of Xperia XZ (f8332) brushing and root
Beisen prospectus: the advantages of the track are prominent, and integration + medium and large customers are plus points
Analyzing the principle of DNS resolution in kubernetes cluster
yolov5
Notes of Teacher Li Hongyi's 2020 in-depth learning series lecture 1
凸优化基础知识
Wine wechat initialization 96% stuck
Zheng Huijuan: Research on application scenarios and evaluation methods of data assets based on the unified market
Piziheng embedded: the method of making source code into lib Library under MCU Xpress IDE and its difference with IAR and MDK
SQLite database operation
基于FPGA的VGA显示
Architecture design of multi live shopping mall
c语言:深度刨析函数栈帧
Flash send email
LP liquidity pledge mining system development detailed procedure
Mandatory interview questions: 1. shallow copy and deep copy_ Deep copy