java 实体
@Data
public class CodeTree{
private Long id;
private String pid;
private String code;
private String name;
private List<CodeTree> children;
}
mapper 接口
// 根据 id 递归查询其子节点(不包含当前节点)
List<CodeTree> listByrecursion(Long id);
映射文件
<resultMap id="RecursionMap" type="com.ws.project.transfer.project.xin.wbs.entity.CodeTree">
<id column="id" jdbcType="LONG" property="id" />
<result column="parent_id" jdbcType="VARCHAR" property="pid" />
<result column="code" jdbcType="VARCHAR" property="code" />
<result column="name" jdbcType="VARCHAR" property="name" />
<collection property="children"
ofType="com.ws.project.transfer.project.xin.wbs.entity.CodeTree"
column="id"
select="listByrecursion" />
</resultMap>
<select id="listByrecursion" resultMap="RecursionMap">
SELECT <include refid="Base_Column_List" /> FROM T_CODE_TREE WHERE PID = #{id}
</select>
标签:String,递归,private,查询,mybatis,id
From: https://www.cnblogs.com/hangychn/p/17592695.html