<?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="com.pz.system.mapper.DepartmentMapper"> <select id="selectDepartmentChildren" resultType="com.pz.system.domain.vo.DepartmentVo"> select id as value,title as text from ( select t1.id,t1.title, if(find_in_set(parent_id, @pids) > 0, @pids := concat(@pids, ',', id), 0) as ischild from ( select id,parent_id,title from department t WHERE t.del_flag = 0 order by parent_id, id ) t1, (select @pids := #{parentId}) t2 ) t3 where ischild != 0 </select> </mapper>