解决mybatis中collection嵌套collection引发的bug
我就废话不多说了,⼤家还是直接看代码吧~
javaType="ArrayList"ofType=""
resultMap="ChildMap"columnPrefix="c_"/>
javaType="ArrayList"ofType=""
resultMap="ToyMap"columnPrefix="t_"/>
,,e,
_Id,Idasc_ParentId,c_Name,easc_Surname,_Age,
_Id,t_Name,st_Color
lect
fromParentp
=Id
=d
=#{id,jdbcType=VARCHAR}
表⾯来看没有任何问题实际查询的child对象中的toys⼀直是空
类关系介绍:
Parent类有属性ArrayList
Child类有属性ArrayList
Toy是⼀个普通的类
原因在于:
javaType="ArrayList"ofType=""
resultMap="ToyMap"columnPrefix="t_"/>
columnPrefix配置的是t_实际mybatis处理后是c_t_
解决办法:
只需要修改sql修改前缀为c_t_即可
_t_Id,c_t_Name,sc_t_Color
补充知识:mybatis嵌套的结果集不能被安全的转为⾃定义ResultHandler的解决办法
sSystemException:orException:
MappedStatementswit
safeResultHandlerEnabled=falttingtobypassthischeck.
问题描述
("All",null,newRowBounds(1,2),resultHandler);
会报不安全,查询Configuration源码发现⾥⾯有⼀个常量是
publicConfiguration(){
wBoundsEnabled=fal;
sultHandlerEnabled=true;//意思是不允许⾃定义ResultHand处理器,
erscoreToCamelCa=fal;
siveLazyLoading=true;
解决办法
publicstaticSqlSessiongetsqlSession(){
SqlSessionssion=ssion();
Configurationconfiguration=figuration();//反射得到configuration,然后
eResultHandlerEnabled(fal);//设置为fal
returnssion;
}
这样就可以了。
以上这篇解决mybatis中collection嵌套collection引发的bug就是⼩编分享给⼤家的全部内容了,希望能给⼤家⼀个参考,也希
望⼤家多多⽀持。
本文发布于:2022-12-27 13:07:57,感谢您对本站的认可!
本文链接:http://www.wtabcd.cn/fanwen/fan/90/40489.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |