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>