我是靠谱客的博主 俏皮大米,这篇文章主要介绍慎用mybatis里的columnPrefix(会导致多层嵌套映射失效),现在分享给大家,希望可以做个参考。

 今天使用单表查省市区三级数据联动,发现mybatis嵌套映射时,第二级的children(也就是第三级 区级别)死活映射不出来数据。

原始配置:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
<resultMap id="AreaResultMap" type="com.jz.own.dev.entity.DevDatadicDetail"> <id column="id" jdbcType="CHAR" property="id" /> <result column="sort" jdbcType="VARCHAR" property="sort" /> <result column="label" jdbcType="VARCHAR" property="label" /> <result column="val" jdbcType="VARCHAR" property="val" /> <result column="pid" jdbcType="VARCHAR" property="pid" /> <result column="order_number" jdbcType="INTEGER" property="orderNumber" /> <result column="del" jdbcType="CHAR" property="del" /> <collection property="children" ofType="com.jz.own.dev.entity.DevDatadicDetail" resultMap="BaseAreaMap" columnPrefix="c_"> <collection property="children" ofType="com.jz.own.dev.entity.DevDatadicDetail" resultMap="BaseAreaMap" columnPrefix="c2_"> </collection> </collection> </resultMap>

 愿因是columnPrefix会使每个子标签内的column属性前面加上对应的前缀,使第二级的children属性对应的collection标签内的column也被加上了前缀(虽然没有指定出来),导致字段不匹配从而无法映射到对象中。

 修改后:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<resultMap id="AreaResultMap" type="com.jz.own.dev.entity.DevDatadicDetail"> <id column="id" jdbcType="CHAR" property="id" /> <result column="sort" jdbcType="VARCHAR" property="sort" /> <result column="label" jdbcType="VARCHAR" property="label" /> <result column="val" jdbcType="VARCHAR" property="val" /> <result column="pid" jdbcType="VARCHAR" property="pid" /> <result column="order_number" jdbcType="INTEGER" property="orderNumber" /> <result column="del" jdbcType="CHAR" property="del" /> <collection property="children" ofType="com.jz.own.dev.entity.DevDatadicDetail"> <id column="c_id" jdbcType="CHAR" property="id" /> <result column="c_sort" jdbcType="VARCHAR" property="sort" /> <result column="c_label" jdbcType="VARCHAR" property="label" /> <result column="c_val" jdbcType="VARCHAR" property="val" /> <result column="c_pid" jdbcType="VARCHAR" property="pid" /> <result column="c_order_number" jdbcType="INTEGER" property="orderNumber" /> <result column="c_del" jdbcType="CHAR" property="del" /> <collection property="children" ofType="com.jz.own.dev.entity.DevDatadicDetail" resultMap="BaseAreaMap" columnPrefix="c2_"> </collection> </collection> </resultMap>

最后

以上就是俏皮大米最近收集整理的关于慎用mybatis里的columnPrefix(会导致多层嵌套映射失效)的全部内容,更多相关慎用mybatis里内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(95)

评论列表共有 0 条评论

立即
投稿
返回
顶部