dao接口的形参是 List<简单类型> 这样的:
ListquaryByIds(@Param("idList") List idList);
select * from student
where 1 = 1
//注意这个集合判空
and id in
#{item}
2.循环list<对象类型>
dao接口的形参是 List<对象类型> 这样的:
ListquaryByxObj(@Param("studentList") List studentList);
mapper文件
额外说明:如果java实现foreach标签的功能,代码如下select * from student where 1=1 and id in #{stu.id}
思路是拼成一个sql的字符串传递给mybatis.
@PostMapping("mybatis/quaryByIds1")
public List quaryByIds1(@RequestBody List idList){
StringBuffer sql = new StringBuffer();
sql.append("select * from student where id in");
sql.append("(");
for (Integer id : idList) {
sql.append(id);//添加id到sql字符串
sql.append(",");//添加成员之间分隔符
}
sql.deleteCharAt(sql.length()-1);//删除最后一个逗号
sql.append(")");
return crudService.quaryByIds1(sql);
}
dao接口
ListquaryByIds1(@Param("sql") StringBuffer sql);
mapper文件



