当前位置:网站首页>@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]
边栏推荐
- Understanding complexity and simple sorting operation
- Notes of Teacher Li Hongyi's 2020 in-depth learning series 8
- Video chat source code - one-to-one live broadcast system source code
- Lidar obstacle detection and tracking: CUDA European clustering
- 痞子衡嵌入式:MCUXpresso IDE下将源码制作成Lib库方法及其与IAR,MDK差异
- Three ways of shell debugging and debugging
- 你还在使用System.currentTimeMillis()?来看看StopWatch吧
- Do you need to open an account to buy a wealth management product with a 6% income?
- 每周小结(*66):下一个五年
- 这个月 google的“AI具备意识”的事件的想法
猜你喜欢

Upload and download filask files

Zheng Huijuan: Research on application scenarios and evaluation methods of data assets based on the unified market
Simple message queue implementation nodejs + redis =mq

Shardingsphere database sub database sub table introduction

C language program environment and preprocessing

Understanding complexity and simple sorting operation

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

Architecture design of multi live shopping mall

Can Baidu network disk yundetectservice.exe be disabled and closed

基于Verilog HDL的数字秒表
随机推荐
Yaml writing rules and comparison between yaml and JSON
Detailed explanation of zhanrui Huben T310: introduce the big core and dynamiq architecture into the entry-level market for the first time!
这个月 google的“AI具备意识”的事件的想法
Learn AI through detectron2
codeforces round #797 ABCDEFG
Digital stopwatch based on Verilog HDL
Excel file processing tool class (based on easyexcel)
BGP related knowledge points
痞子衡嵌入式:MCUXpresso IDE下将源码制作成Lib库方法及其与IAR,MDK差异
技术操作
指针与数组
Horizontally centered element
NVIDIA inspector detailed instructions
线段树杂谈
[Nuxt 3] (十)运行时配置
How to propose effective solutions for high-end products? (1 methodology + 2 cases + 1 List)
First experience of flask
每周小结(*66):下一个五年
1. Smoke test
From the big guy baptism! 2022 headline first hand play MySQL advanced notes, and it is expected to penetrate P7