mybatis 如何利用resultMap复杂类型list映射

mybatis resultMap复杂类型list映射

映射泛型为对象

xml


    
    
    
        
        
        
        
    
 
 

DTO

@Data
public class StrategyInternetDataDTO { 
    private Integer id ;
    private Integer internetData ;
    private List userList ;
 
}

ENTITY

@Data
public class SysUser { 
    private Integer id;
    private String number;
    private String pushToken;
    private String wsChannelId ; 
}

MAPPER

List selectInternetDataDTOByInternetDataIdList(@Param("internetDataIdList") List internetDataIdList);

映射泛型为包装类型

xml


    
    
    
        
    
  
 

DTO

@Data
public class StrategyInternetDataDTO { 
    private Integer id ;
    private Integer internetData ;
    private List userIdList ; 
}

MAPPER

List selectInternetDataDTOByInternetDataIdList(@Param("internetDataIdList") List internetDataIdList);

mybatis的几种传值方式

1.单个参数传参

User selectUserInfo(Integer userId);

2. 按照顺序传参

User selectUserInfo(Integer userId, String userName, String userPass);

3. 使用@Param注解传参

User selectUserInfo(@Param("userName")String userName, @Param("userPass")String userPass);

4. 使用Map传参 注意传参方式:parameterType="java.util.Map"

Map map = new HashMap();
map.put("userName","张三");
map.put("userPass","123");
User user = userMapper.selectUserInfo(map);
User selectUserInfo(Map map);

5. 实体对象传参

User user = new User();
user.setUserName("张三");
user.setUserPass("123");
User user = UserMapper.selectUserInfo(user);
User selectUserInfo(User record);

6. List传参

List list = new ArrayList<>();
list.add(user1);
list.add(user2);
List userList = userMapper.selectUserInfo(list);
    
List selectUserInfo(List record);

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

你可能感兴趣的:(mybatis 如何利用resultMap复杂类型list映射)