MyBatis提供了以下几种传入List的方法:
- 使用List作为参数,传入多个值。在Mapper接口的方法中,可以直接使用List作为参数,并在SQL语句中使用foreach循环遍历List中的值。
public interface UserMapper { ListgetUserList(List ids); }
- 使用数组作为参数,传入多个值。与List类似,只需要将List替换为数组即可。
public interface UserMapper { ListgetUserList(String[] ids); }
- 使用包装类作为参数,传入多个值。可以定义一个包装类,将多个值封装到该类中,并在Mapper接口的方法中使用该包装类作为参数。
public class IdListWrapper { private Listids; // getter and setter } public interface UserMapper { List getUserList(IdListWrapper idListWrapper); }
这些方法都可以实现传入List的功能,根据具体的需求选择适合的方法即可。