本文章记录两种方式获取部门树型结构
一、使用mybatis,因循环查库,比较耗时,
二、递归查询
一、使用mybatis实现
1.编写实体类,TreeVO.java
@Data
public class TreeVO {
private String value;
private String label;
private List<TreeVO> children = new ArrayList<>();
}
2.编写sql 语句,CommonMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="CommonMapper">
<resultMap id="BaseResultMap" type="TreeVO">
<result property="value" column="id"/>
<result property="label" column="name"/>
<!--这里使用mybatis collection 进行集合查询 这是关键点-->
<collection property="children" javaType