collection什么意思

更新时间:2022-12-27 13:07:57 阅读: 评论:0


2022年12月27日发(作者:泰坦尼克号歌词)

解决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类有属性ArrayListchildren

Child类有属性ArrayListtoys

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小时内删除。

下一篇:meant
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图