Mybatis传入 List<Map<String,Object>>的入参
程序员文章站
2022-06-30 20:50:02
...
直接上代码吧:
service层:
Map<String,Object> paramMap = new HashMap<>();
List<Map<String,Object>> paramMapList = new ArrayList<>();
for(ChannelParam channelParam:paramList){
paramMap.put("device_serial",channelParam.getDeviceSerial());
paramMap.put("channel_no",channelParam.getChannelNo());
paramMapList.add(paramMap);
}
List<DeviceChannel> deviceChannelList = channelMapper.selectListByChannel(paramMapList);
备注:这里的ChannelParam类是个实体类
@Data
public class ChannelParam {
private String deviceSerial;
private Integer channelNo;
}
mapper层:
List<DeviceChannel> selectListByChannel(List<Map<String,Object>> paramMapList);
sql配置文件:
<select id="selectListByChannel" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from device_channel
where
<foreach item="item" index="key" collection="list"
open="" separator="OR" close="">
device_serial=#{item.device_serial} and
channel_no = #{item.channel_no}
</foreach>
</select>
解释一下: collection这里用的是list,这个是mybatis源码中默认的,非list用collection,可以跟进源码看看
item.device_serial 和 item.channel_no 就相当于 获取map的key名和value
上一篇: js基础深入总结
下一篇: Linux ping命令详解
推荐阅读
-
jdbc查询返回来的List
-
Mybatis传入 List<Map<String,Object>>的入参
-
mybatis 插入List<Map<String, Object>> 出现__frch_list_0异常
-
mybatis_批量插入参数List_Map_String,Object
-
map入参mybatis,并用List返回
-
mybatis传入多个参数Lis(Map(String,Object))type handler was null on parameter mapping for property
-
Mybatis 如何 返回 List
类型 或 List -
Mybatis实现查询返回List《Map《String,Object》》格式数据(标题不让打尖括号)
-
mybatis 不依赖实体列名,使用List<Map<String,Object>>返回多条记录
-
mybatis 查询返回List<String>、Map<String,Object>、List<Map<String,Object>>