mybatis中foreach详解(传参Map类型)

来源:互联网 发布:北上广失败的数据 编辑:程序博客网 时间:2024/06/05 21:03

项目遇到:需要根据一个字段的集合遍历查询数据,需要在mybatis使用传入个Map<String Object>参数进行foreach遍历查询。

xml代码如下:

<select id="selectByMr" resultMap="BaseResultMap">select <include refid="Base_Column_List"/>from cell_info<where><foreach collection="coverage" item="item" index="index" open="and objectid in(" separator="," close=")">#{item}</foreach></where></select>
其中,collection的值是coverage,是传入的参数Map的key。


mapper代码如下:

List<Cell_info> selectByMr(Map<String, Object> map);

serviceImpl代码如下:

@Overridepublic List<Cell_info> searchWeakCoverage(Map<String, Object> map,Page page) {List<Cell_info> cellList = null;Map<String, Object> mapL = new HashMap<String, Object>();List<String>  list = complaintsAnalysisDao.searchWeakCoverage(map);//查询多条结果,当做查询条件if(0!=list.size()){mapL.put("coverage", list);mapL.put("page", page);//分页用的cellList = cellInfoDao.selectByMr(mapL);}return cellList;}


0 0
原创粉丝点击