mybatis dao层集合传参 1 List<Student > listStudentByIds(Set<Long > ids);
1 2 3 4 5 6 7 8 9 10 <select id ="findNameAndPhoneByPersonId" > SELECT IDENTITY_NAME, USER_PHONE FROM PERSON WHERE PERSON_ID IN <foreach collection ="list" index ="index" item ="item" 错误 open ="(" separator ="," close =")" > #{item} </foreach > AND DEL_FLAG=0 </select >
查看源码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 private Object wrapCollection (Object object) { DefaultSqlSession.StrictMap map; if (object instanceof Collection) { map = new DefaultSqlSession .StrictMap(); map.put("collection" , object); if (object instanceof List) { map.put("list" , object); } return map; } else if (object != null && object.getClass().isArray()) { map = new DefaultSqlSession .StrictMap(); map.put("array" , object); return map; } else { return object; } }
这里明显就表明:
传入参数为list集合时 : collection = “list”
传入参数为array集合时 : collection = “array”
传入参数为其他集合时 : collection = “collection” 显而易见,将collection改为”collection”即可
参考链接:
https://blog.csdn.net/qq_48496989/article/details/121532210