转载自 mybatis 注解传入 list 集合
这里写一个查询的sql语句
首先看 mapper
@SelectProvider(type = SqlModel.class, method = "listDeviceIndex")@Results(value = {@Result(column = "index_id",property = "userIndex"),@Result(column = "device_id",property = "deviceId")})List<DeviceIndex> selectByDeviceIdList(List<Integer> deviceIds);
@SelectProvider是生产动态sql的
type : 对应的类
method : 方法
SqlModel.java
public String listDeviceIndex(Map map) {List<Integer> list = (List<Integer>) map.get("list");StringBuilder sb = new StringBuilder();sb.append("SELECT * FROM device_index WHERE device_id IN(");MessageFormat mf = new MessageFormat("#'{'list[{0}]}");for (int i = 0; i < list.size(); i++) {sb.append(mf.format(new Object[]{i}));if (i < list.size() - 1) {sb.append(",");}}sb.append(")");return sb.toString();}