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

网友投稿 756 2022-12-23

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

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

mybatis resultMap复杂类型list映射

映射泛型为对象

xml

SELECT sidu.id, sidu.internet_data, su.id, su.number, su.push_token, su.ws_channel_id

FROM strategy_internet_data_user sidu JOIN skr_user su on su.id = sidu.user_id

WHERE sidu.id IN

separator="," item="internetDataId">

#{internetDataId}

separator="," item="internetDataId">

#{internetDataId}

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

SELECT sidu.id, sidu.internet_data, sidu.user_id userId

FROM strategy_internet_data_user sidu

WHERE sidu.id IN

separator="," item="internetDataId">

#{internetDataId}

separator="," item="internetDataId">

#{internetDataId}

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);

select

from user

where userId = #{userId , jdbcType=INTEGER}

2. 按照顺序传参

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

select

from user

where userId = #{arg0} and userName = #{arg1} and userPass = #{arg2}

3. 使用@Param注解传参

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

select

from user

where userName = #{userName} and userPass = #{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);

select

from user

where userName = #{userName} and userPass = #{userPass}

5. 实体对象传参

User user = new User();

user.setUserName("张三");

user.setUserPass("123");

User user = UserMapper.selectUserInfo(user);

User selectUserInfo(User record);

select

from user

where userName = #{userName} and userPass = #{userPass}

6. List传参

List list = new ArrayList<>();

list.add(user1);

list.add(user2);

List userList = userMapper.selectUserInfo(list);

List selectUserInfo(List record);

select

from user

where userId in

#{item}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:包含flutter高级工程师面试的词条
下一篇:重庆智能车载终端报价(重庆智能车源中心)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~