mybatis XML中 遍历map写法

时间:2023-03-08 19:06:11
   <select id="selectMapTest" parameterType="java.util.HashMap" resultMap="BaseResultMap">
<foreach collection="map1" index="key" item="ent" separator="union">
SELECT *
FROM User
where username=#{key}
and userpass in
<foreach collection="ent" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</foreach> </select>

 对应的mapper中是:

//map测试
List<User> selectMapTest(@Param("map1") Map<String,List<Integer>> ma1); 注意:foreach标签中的index就是map的key值