Mybatis遇到List传值时常用方法。
1. List<E>,E为基本数据类型和String
Mapper类文件:
List selectByIds(List userList);
Mapper.xml文件:
测试结果:
![]()
2. List<E>,E为Object对象
2.1 不配合@param使用
Mapper类文件:
List selectUser1(List userList);
Mapper.xml文件:
测试结果:
![]()
2.2 配合@param使用,自定义参数名
Mapper类文件:
List selectUser2(@Param("userList") List userList);
Mapper.xml文件:
测试结果:
![]()
3. Map<k,V>,V为List对象
3.1 不配合@param使用
Mapper类文件:
List selectByMap1(Map<String,List> paramMap);
Mapper.xml文件:
测试结果:
![]()
3.2 配合@param使用,自定义参数名
Mapper类文件:
List selectByMap2(@Param("mapList") Map<String,List> paramMap);
Mapper.xml文件:
测试结果:
![]()