当前位置:网站首页>resulttype和resultmap的区别和应用场景
resulttype和resultmap的区别和应用场景
2022-07-06 03:00:00 【thoughtCodes】
项目场景:
提示:这里简述项目相关背景:
很开心,又用比较方法解决了这个问题,还是原来解决问题的方法:
1.查2比3累计
问题描述
提示:这里描述项目中遇到的问题:
一、看到这个问题,你可能以为是实体类未在mybatis-config.xml中配置别名(alias)导致的,如下图所示:
进过对比之后,我发现自己的resultMap写成了resultType
原因分析:
提示:这里填写问题的分析:
MyBatis中在查询进行select映射的时候,返回类型可以用resultType,也可以用resultMap,resultType是直接表示返回类型的,而resultMap则是对外部ResultMap的引用,但是resultType跟resultMap不能同时存在。
在MyBatis进行查询映射时,其实查询出来的每一个属性都是放在一个对应的Map里面的,其中键是属性名,值则是其对应的值。
①当提供的返回类型属性是resultType时,MyBatis会将Map里面的键值对取出赋给resultType所指定的对象对应的属性。所以其实MyBatis的每一个查询映射的返回类型都是ResultMap,只是当提供的返回类型属性是resultType的时候,MyBatis对自动的给把对应的值赋给resultType所指定对象的属性。
而且这里是大写对应的map,小写的名字对应的map数值
②当提供的返回类型是resultMap时,因为Map不能很好表示领域模型,就需要自己再进一步的把它转化为对应的对象,这常常在复杂查询中很有作用。
解决方案:
提示:这里填写该问题的具体解决方案:
我填写resulttype 是没问题,赋值出了问题,但是resultMap 会映射的应用的。over. 2个问题已经解决了。
边栏推荐
- A copy can also produce flowers
- 【若依(ruoyi)】ztree 自定义图标(iconSkin 属性)
- Redis skip table
- RobotFramework入门(二)appUI自动化之app启动
- Descriptor implements ORM model
- Apt installation ZABBIX
- Summary of Bible story reading
- MySQL advanced notes
- Pat 1046 shortest distance (20 points) simulation
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22
猜你喜欢
2022工作中遇到的问题四
Who is the winner of PTA
My C language learning record (blue bridge) -- under the pointer
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 22
Microsoft speech synthesis assistant v1.3 text to speech tool, real speech AI generator
[ruoyi] set theme style
Fault analysis | analysis of an example of MySQL running out of host memory
【Kubernetes 系列】一文学会Kubernetes Service安全的暴露应用
RobotFramework入门(三)WebUI自动化之百度搜索
XSS challenges绕过防护策略进行 XSS 注入
随机推荐
【Kubernetes 系列】一文学会Kubernetes Service安全的暴露应用
技术分享 | undo 太大了怎么办
Patch NTP server at the beginning of DDoS counterattack
Day 50 - install vsftpd on ceontos6.8
js 正则过滤和增加富文本中图片前缀
Summary of Bible story reading
Follow the mouse's angle and keyboard events
"Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.5 automatic differentiation_ Learning thinking and exercise answers
Pat 1046 shortest distance (20 points) simulation
[matlab] access of variables and files
JS events (add, delete) and delegates
主数据管理(MDM)的成熟度
1003 emergency (25 points), "DIJ deformation"
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 16
Network Security Learning - Web vulnerabilities (Part 1)
微软语音合成助手 v1.3 文本转语音工具,真实语音AI生成器
纯Qt版中国象棋:实现双人对战、人机对战及网络对战
Pat 1084 broken keyboard (20 points) string find
如何精准识别主数据?
【Kubernetes 系列】一文學會Kubernetes Service安全的暴露應用