mybatis xml如下:
<select id="queryChildDeptInfoByDid" parameterType="string" resultType="HashMap">
select
a.dept_id,a.parent_id
from sys_dept a where 1=1
start with
a.dept_id = #{deptId}
connect by
prior a.dept_id = a.parent_id
</select>
<select id="queryDeptInfoList" resultType="HashMap" parameterType="HashMap">
select * from sys_dept A
<where>
<if test="deptIds != null and deptIds!=''">
AND A.DEPT_ID IN
<foreach item="item" index="index" collection="deptIds" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</where>
</select>
dao层:
@MyBatisDao
public interface SysDeptDao extends CrudDao<SysDept> {
...
//递归查询部门及子部门信息
List<HashMap<String,Object>> queryChildDeptInfoByDid(String deptId);
//条件查询部门
List<HashMap<String,Object>> queryDeptInfoList(HashMap<String,Object> params);
...
}
Service层:
@Service
@Transactional(readOnly = true)
public class SysDeptService extends CrudService<SysDeptDao, SysDept> {
public Page findPage(Page page, HashMap<String, Object> paramsMap) {
String deptId=paramsMap.get("deptId")==null?"":paramsMap.get("deptId").toString();
List<HashMap<String,Object>>resultList1=dao.queryChildDeptInfoByDid(deptId);
String [] cIdArray = {"-1"};
List<String> deptList1=new ArrayList<String>();
if(!StringUtils.isBlank(deptId) && resultList1!=null && resultList1.size()>0){
for(HashMap<String,Object> m:resultList1){
deptList1.add(m.get("deptId").toString());
}
cIdArray=deptList1.toArray(new String[deptList1.size()]);
}
paramsMap.put("deptIds",cIdArray);
page.setRecords(dao.queryDeptInfoList(page,paramsMap));
return page;
}
}