当前位置:网站首页>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>
边栏推荐
- xargs命令的基本用法
- Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
- 多元聚类分析
- LeetCode:39. Combined sum
- [text generation] recommended in the collection of papers - Stanford researchers introduce time control methods to make long text generation more smooth
- An article takes you to understand the working principle of selenium in detail
- Booking of tourism products in Gansu quadrupled: "green horse" became popular, and one room of B & B around Gansu museum was hard to find
- 自定义卷积注意力算子的CUDA实现
- Le modèle sentinelle de redis
- [shell script] use menu commands to build scripts for creating folders in the cluster
猜你喜欢
Pytest参数化你不知道的一些使用技巧 /你不知道的pytest
Sentinel mode of redis
Advance Computer Network Review(1)——FatTree
Redis geospatial
Problems encountered in connecting the database of the project and their solutions
【shell脚本】——归档文件脚本
Redis' performance indicators and monitoring methods
Pytest parameterization some tips you don't know / pytest you don't know
Ijcai2022 collection of papers (continuously updated)
Different data-driven code executes the same test scenario
随机推荐
Mongodb installation and basic operation
使用标签模板解决用户恶意输入的问题
[OC]-<UI入门>--常用控件-提示对话框 And 等待提示器(圈)
KDD 2022论文合集(持续更新中)
IDS' deletion policy
[OC-Foundation框架]---【集合数组】
What is MySQL? What is the learning path of MySQL
Redis之连接redis服务命令
[OC-Foundation框架]--<Copy对象复制>
Intel Distiller工具包-量化实现2
Blue Bridge Cup_ Single chip microcomputer_ PWM output
[OC]-<UI入门>--常用控件的学习
Li Kou daily question 1 (2)
CUDA实现focal_loss
Parameterization of postman
Reids之缓存预热、雪崩、穿透
Booking of tourism products in Gansu quadrupled: "green horse" became popular, and one room of B & B around Gansu museum was hard to find
[OC]-<UI入门>--常用控件-UIButton
[shell script] use menu commands to build scripts for creating folders in the cluster
What is an R-value reference and what is the difference between it and an l-value?