当前位置:网站首页>Solve the problem of inconsistency between database field name and entity class attribute name (resultmap result set mapping)
Solve the problem of inconsistency between database field name and entity class attribute name (resultmap result set mapping)
2022-07-06 09:17:00 【c-vking】
problem
Database fields :id name pwd
Entity class properties :id name password
Query results :password Query as null
reason :
sql sentence :select * from mybatis.user where id = #{id}
It's actually :select id,name,pwd from mybatis.user where id = #{id}
And the output user Of password Property has no assignment , So for null
resolvent :
1. names ( understand )
select id,name,pwd as password from mybatis.user where id = #{id}
2. Use resultMap Result set mapping
<resultMap id="userMap" type="user">
<!--property Properties in entity classes ,column Fields in the database -->
<result property="password" column="pwd"/>
</resultMap>
<select id="getUserById" resultMap="userMap" parameterType="int">
select * from mybatis.user where id = #{id}
</select>
边栏推荐
- Using label template to solve the problem of malicious input by users
- What is MySQL? What is the learning path of MySQL
- 【文本生成】论文合集推荐丨 斯坦福研究者引入时间控制方法 长文本生成更流畅
- CUDA implementation of self defined convolution attention operator
- 数学建模2004B题(输电问题)
- requests的深入刨析及封装调用
- Advance Computer Network Review(1)——FatTree
- Redis core configuration
- Notes 01
- Go redis initialization connection
猜你喜欢
QML type: locale, date
【shell脚本】——归档文件脚本
Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
Redis之哨兵模式
[OC]-<UI入门>--常用控件的学习
Nacos installation and service registration
不同的数据驱动代码执行相同的测试场景
LeetCode41——First Missing Positive——hashing in place & swap
In depth analysis and encapsulation call of requests
数学建模2004B题(输电问题)
随机推荐
QDialog
Advanced Computer Network Review(4)——Congestion Control of MPTCP
Redis' performance indicators and monitoring methods
LeetCode:836. Rectangle overlap
LeetCode:124. Maximum path sum in binary tree
Selenium+Pytest自动化测试框架实战(下)
Ijcai2022 collection of papers (continuously updated)
[oc]- < getting started with UI> -- learning common controls
Li Kou daily question 1 (2)
Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
Redis之发布订阅
Basic usage of xargs command
Selenium+pytest automated test framework practice (Part 2)
LeetCode:214. Shortest palindrome string
LeetCode:34. Find the first and last positions of elements in a sorted array
Kratos战神微服务框架(三)
BMINF的後訓練量化實現
Intel distiller Toolkit - Quantitative implementation 2
【图的三大存储方式】只会用邻接矩阵就out了
七层网络体系结构