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

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;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值