1.1、List参数在mybatis的foreach写法如下代码:
<select id="getObjByProductId" parameterType="java.util.List" resultType="String">
SELECT
GROUP_CONCAT(
CONCAT_WS(
'-',
Province,
City,
Area
) SEPARATOR ','
) AS zone
FROM
table
where
ID IN
<foreach collection="productids" item="id" index="index" open="(" close=")" separator=",">
#{id}
</foreach>
</select>
1.2、对应的mapper(Dao)
public String getObjByProductId(@Param("productids") List<String> productids);
2.1、Set参数在mybatis的foreach写法也一样
<select id="getUniqueObjByState" resultType="String" parameterType="java.util.Set">
<if test="set != null">
SELECT
City
FROM
table WHERE ID IN
<foreach collection="set" index="index" open="(" close=")" separator="," item="setObj">
#{setObj}
</foreach>
</if>
</select>
2.2、对应的mapper(Dao)
public List<String> getUniqueObjByState(@Param("set") Set<String> set);
注:parameterType不同,foreach循环的写法一样。