传入List时,xml通过<foreach>标签实现sql in

67 阅读1分钟

mapper层

dept selectByDepeIds ( @Param("deptIds") List deptIds);

xml

<select id="selectByDepeIds" resultType="dept">
    SELECT * from dept 
    <if test="deptIds!=null and deptIds.size()> 0">
        WHERE deptId in
        <foreach  item="item" index="index" collection="deptIds" open="(" separator="," close=" )">
            #{item}
        </foreach>
    </if>
</select>
```
```