当前位置:网站首页>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个问题已经解决了。
边栏推荐
- 技术分享 | undo 太大了怎么办
- [unity3d] GUI control
- 【Kubernetes 系列】一文学会Kubernetes Service安全的暴露应用
- Installation and use tutorial of cobaltstrike-4.4-k8 modified version
- 有没有完全自主的国产化数据库技术
- 纯Qt版中国象棋:实现双人对战、人机对战及网络对战
- Referenceerror: primordials is not defined error resolution
- A copy can also produce flowers
- Is there a completely independent localization database technology
- Technology sharing | what if Undo is too big
猜你喜欢
Introduction to robotframework (II) app startup of appui automation
CobaltStrike-4.4-K8修改版安装使用教程
Yyds dry inventory comparison of several database storage engines
MySQL advanced notes
[kubernetes series] learn the exposed application of kubernetes service security
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 23
Installation and use tutorial of cobaltstrike-4.4-k8 modified version
Solution: attributeerror: 'STR' object has no attribute 'decode‘
I sorted out a classic interview question for my job hopping friends
1. Dynamic parameters of function: *args, **kwargs
随机推荐
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 17
Codeworks 5 questions per day (1700 average) - day 6
[ruoyi] enable Mini navigation bar
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 9
PMP每日一练 | 考试不迷路-7.5
GifCam v7.0 极简GIF动画录制工具中文单文件版
Installation and use tutorial of cobaltstrike-4.4-k8 modified version
[unity3d] GUI control
Follow the mouse's angle and keyboard events
[network security interview question] - how to penetrate the test file directory through
原型图设计
深度解析链动2+1模式,颠覆传统卖货思维?
Detailed use of dbutils # yyds dry goods inventory #
【 kubernets series】 a Literature Study on the Safe exposure Applications of kubernets Service
XSS challenges bypass the protection strategy for XSS injection
建模规范:命名规范
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
Apt installation ZABBIX
Briefly describe the implementation principle of redis cluster
Rust language -- iterators and closures