mybatis foreach标签使用之IN

需求SQL:SELECT * FROM USER WHERE id IN (1,2,3)

(ids和对应入参变量名对应)

<select id="findByIds"  resultType="user">
SELECT * FROM USER
<where>
<foreach collection="ids" open="id IN (" separator="," item="i"
close=")">
#{i}
</foreach>
</where>
</select>
//根据学生ids查询
    List<User> listByIds(@Param("ids") List<Long> ids);

 

相关推荐
©️2020 CSDN 皮肤主题: 游动-白 设计师:白松林 返回首页