Oracle start with用法实例之根据当前部门id递归查询该部门及子部门信息实例

来源:互联网 发布:迫击炮威力 知乎 编辑:程序博客网 时间:2024/05/18 03:52

1.实体bean(对应数据库表sys_dept结构为:dept_id、parent_id…)

public class Dept{    private String deptId;          // 部门ID    private String parentId;        // 上级部门ID    ...    (    getter...    setter...    )    ...

2.mybatis xml配置如下:

<select id="findList" resultType="HashMap">    select     a.dept_id,    a.parent_id    from sys_dept a    <where>        <if test="deptId!= null and deptId!= ''">            AND a.dept_id in            (            select             b.dept_id             from sys_dept b  where 1=1            start with             b.dept_id= #{deptId}            connect by prior b.dept_id=  b.parent_id            )        </if>        <if test="parentId!= null and parentId!= ''">            AND a.parent_id=#{parentId}        </if>    </where></select>
阅读全文
0 0
原创粉丝点击