您的位置:首页 > 编程语言

关于mybatis xml中用in、start with查询数据代码片段

2017-08-31 11:23 162 查看
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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐