关于mybatis xml中用in、start with查询数据代码片段
2017-08-31 11:23
162 查看
mybatis xml如下:
dao层:
Service层:
<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; } }
相关文章推荐
- 03_MyBatis基本查询,mapper文件的定义,测试代码的编写,resultMap配置返回值,sql片段配置,select标签标签中的内容介绍,配置使用二级缓存,使用别名的数据类型,条件查询ma
- 03_MyBatis基本查询,mapper文件的定义,测试代码的编写,resultMap配置返回值,sql片段配置,select标签标签中的内容介绍,配置使用二级缓存,使用别名的数据类型,条件查询ma
- Silverlight 3 关于数据添加,删除,修改,条件查询的一点代码
- 关于hibernate中如何实现limit查询,就要考测试了,我还在调代码
- 关于oracle查询用in不能超过1000条的解决办法
- MySQL查询本周、上周、本月、上个月份数据的sql代码
- Hibernate中,将session绑定到线程时,在保存和查询数据的代码里,要正确的关闭session
- sql查询按in顺序排序显示数据 oracle
- 数据结构关于树的一些递归函数代码
- 关于Hibernate映射视图后数据查询的方法
- Android 防止多次点击提交数据(文章或评论)代码片段
- org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [WebApp] in context with path关于数据库库的问题
- 关于地图的操作的代码片段
- 关于php udp当服务端接受不同数据的代码
- 关于SQL查询效率,100w数据,查询只要1秒
- Ajax发送json格式数据到Asp.net MVC服务端的一些代码片段
- OA项目中关于数据表递归查询
- 关于模糊查询时的索引问题.(了解一下,对提高代码效率非常有好处)
- 关于pgsql 的json 和jsonb 的数据查询操作笔记整理
- 关于ajax图片上传,上传是后台代码来完成的,利用ajaxSubmit来完成,前台只是负责提交数据