在MyBatis中,可以使用foreach标签来实现传递in参数,具体方法如下:
foreach标签包裹需要传递的参数,如下所示:<select id="selectByIdList" resultMap="BaseResultMap"> SELECT * FROM users WHERE id IN <foreach item="item" index="index" collection="idList" open="(" separator="," close=")"> #{item} </foreach></select>在对应的Mapper接口中,定义方法并传入idList参数,如下所示:public List<User> selectByIdList(@Param("idList") List<Integer> idList);通过以上方法,可以实现将idList参数传递给SQL语句中的IN语句,实现批量查询操作。


