当前位置:网站首页>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>
边栏推荐
- 数学建模2004B题(输电问题)
- Redis geospatial
- [oc]- < getting started with UI> -- common controls - prompt dialog box and wait for the prompt (circle)
- Intel distiller Toolkit - Quantitative implementation 1
- Kratos战神微服务框架(二)
- Intel distiller Toolkit - Quantitative implementation 3
- Seven layer network architecture
- 【shell脚本】——归档文件脚本
- ant-design的走马灯(Carousel)组件在TS(typescript)环境中调用prev以及next方法
- Intel Distiller工具包-量化实现2
猜你喜欢
一篇文章带你了解-selenium工作原理详解
Redis' bitmap
CUDA realizes focal_ loss
什么是MySQL?MySql的学习之路是怎样的
Simclr: comparative learning in NLP
Redis之哨兵模式
[oc foundation framework] - < copy object copy >
Parameterization of postman
Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
[sword finger offer] serialized binary tree
随机推荐
KDD 2022论文合集(持续更新中)
【文本生成】论文合集推荐丨 斯坦福研究者引入时间控制方法 长文本生成更流畅
MySQL uninstallation and installation methods
The carousel component of ant design calls prev and next methods in TS (typescript) environment
xargs命令的基本用法
LeetCode:673. Number of longest increasing subsequences
SimCLR:NLP中的对比学习
[oc foundation framework] - < copy object copy >
Kratos ares microservice framework (I)
Reids之删除策略
Mise en œuvre de la quantification post - formation du bminf
Redis之性能指标、监控方式
Opencv+dlib realizes "matching" glasses for Mona Lisa
如何正确截取字符串(例:应用报错信息截取入库操作)
Le modèle sentinelle de redis
Kratos ares microservice framework (III)
Redis之持久化实操(Linux版)
Basic usage of xargs command
LeetCode:34. Find the first and last positions of elements in a sorted array
What is MySQL? What is the learning path of MySQL