MyBatis使用foreach

代码如下:

1
2
3
4
5
6
7
8
9

@Mapper
public interface CommonMaterialMapper extends BaseMapper<CommonMaterial> {

    @Select("<script>select * from t_common_material where id in <foreach collection='ids' item='id' open='(' separator=',' close=')'> #{id} </foreach></script>")
    List<CommonMaterial> selectListWithDelete(@Param("ids") List<String> ids);

}

参考资料

  1. Mybatis @Select注解,使用in传入ids数组作为参数