mybatis递归查询笔记
来源:互联网 发布:qt编程下载 编辑:程序博客网 时间:2024/05/22 12:22
今天前端需要我提供一个树状数据接口。想到了mybatis有collection可以使用。
但是使用时,child数据一直为null
原代码如下:
<resultMap id="waresTypeTreeMap" type="WaresTypeTreeEntity"><id column="pk_base_wares_type_id" property="id" jdbcType="BIGINT" /><result column="wares_type_name" property="text" jdbcType="VARCHAR" /><collection property="nodes" column="id" ofType="WaresTypeTreeEntity" select="queryTreeWaresTypeList" /> </resultMap>
<select id="queryTreeWaresTypeList" resultMap="waresTypeTreeMap">select t.pk_base_wares_type_id,t.wares_type_namefrom t_base_wares_type twhere t.parent_id =#{waresTypeId,jdbcType=BIGINT}</select>
根据经验判断应该是collection的column没传值导致,然后走了很多弯路,发现都不行。
最后无意间把 result 里的column及property改成一致,发现有效。
于是发现问题所在:collection里的column应该传的是 result里的 column,而不是property。
虽然传property不报错,但是mybatis collection是在转换成VO对象前触发的。
也就是说id一直为null。故child也是null值。
修改后代码如下:
<resultMap id="waresTypeTreeMap" type="WaresTypeTreeEntity"><id column="pk_base_wares_type_id" property="id" jdbcType="BIGINT" /><result column="wares_type_name" property="text" jdbcType="VARCHAR" /><collection property="nodes" column="pk_base_wares_type_id" ofType="WaresTypeTreeEntity" select="queryTreeWaresTypeList" /> </resultMap>
0 0
- mybatis递归查询笔记
- mybatis+mysql递归查询
- mybatis中collection的使用,递归查询
- Mybatis自查询递归查找子菜单
- LigurUi + spring mybatis mysql 菜单递归查询
- mybatis学习笔记--分页查询
- 博为峰JavaEE技术文章 ——MyBatis 递归查询
- MyBatis之自查询,使用 递归实现 N级联
- mybatis+mysql查询类别下的所有子类别(递归)
- mybatis+mysql查询大类别下的所有图书(递归)
- JAVA学习笔记0008----递归查询目录
- 用户层级递归查询的笔记
- mybatis学习笔记一(简单的查询)
- MyBatis学习笔记(八)分页查询
- MyBatis学习笔记(五)关联查询
- mybatis学习笔记(10)-一对一查询
- mybatis学习笔记(11)-一对多查询
- Mybatis学习笔记---day02关联关系查询
- 修改导航条返回按钮的思考
- 运行程序时,提示模拟器的minSdk != deviceSdk,但是minsdk的设置是小于模拟器版本的
- Node.js可以做什么? Node.js究竟是什么?
- android 微信支付 + node.js 服务端
- 算法 —— 回溯法
- mybatis递归查询笔记
- 【38】java的集合框架(容器框架)
- 【3329】顺序表应用5:有序顺序表归并
- 用type定义的枚举类型和结构体
- Element is not clickable at point (1108, 190). Other element would receive the click
- R - Milking Time——POJ C语言实现
- CSS3那些不为人知的高级属性
- NSTimer的误差问题
- msyql关于大于号和order by