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

项目遇到:需要根据一个字段的集合遍历查询数据,需要在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代码如下:

@Override
	public 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;
	}


你可能感兴趣的:(mybatis)