如果你不但需要传入map作为参数去sql中遍历,还需要传入别的参数
1,首先,传入map的遍历方式
把要传入的map转换为如下的形式
Map<String,Map<String,String>> map = new HashMap<>();
mabatis遍历中
<foreach collection="Map_Name" item="value" index="key">
sql语句
</foreach>
2,map的解决了,那么其他的参数怎么获取呢?我是这么解决的
仿照1的做法,把其他的参数也放到map中
Map<String,Object> map = new HashMap<>();
map.put("参数名","参数值");
再把这个map也添加到1中的大map中去,取值的时候也需要用foreach的方式取值,
3,坑点
注意在一个sql中,两个foreach的 item 和 index 的变量名,不要一样,一样的话会报下面的错
source is null for getProperty(null, "name")
<foreach collection="Map_Name1" item="value1" index="key1">
sql语句
</foreach>
<foreach collection="Map_Name2" item="value2" index="key2">
sql语句
</foreach>