实现MyBatis批量查询
Service
public List<DeviceBean> getDeviceList(Map<String, Object> parameter);
ServiceImpl
@Override
public Map<String, DeviceBean> getDeviceCollectStateIdByBean(Map<String, Object> parameter) {
logger.info("DeviceServiceImpl{}==>getDeviceCollectStateIdByBean()");
return deviceDao.getDeviceCollectStateIdByBean(parameter);
}
Dao
public List<DeviceBean> getDeviceList(Map<String, Object> parameter);
DaoImpl
@Override
public List<DeviceBean> getDeviceList(Map<String, Object> parameter) {
logger.info("DeviceDaoImpl{}==>getDeviceList()");
return getWriteSession().selectList(sqlId("getDeviceList"),parameter);
}
Mapper
<select id="getDeviceList" resultType="com.yjkj.zzx.system.bean.DeviceBean" parameterType="map" >
select
d.id as id, d.group_id as groupId,d.farm_id as farmId, d.house_id as houseId, d.code
from t_device d
WHERE d.del_flag = '0' and d.code in
<foreach item="item" index="index" collection="codelist" open="(" separator="," close=")">
#{item}
</foreach>
</select>
测试打印结果
List<String> codeList =new ArrayList<String>();
codeList.add("b827ebee9322");
codeList.add("111");
codeList.add("1111");
Map<String,Object> paramap=new HashMap<String,Object>();
paramap.put("codelist", codeList);
List<DeviceBean> res11 = deviceService.getDeviceList(paramap);
System.out.println(res11);