mybatis 多参数的使用

UserDao.java dao中,函数的参数需要设置@Param

 
List<User> getUsers(@Param("teamMember")User user, @Param("teamIds")List<Long> teamIds);

mapper.xml 中,使用  

对象.  的形式获取参数 (如:teamMember.teamId)

teamIds != null and teamIds.size() > 0 判断list是否为空以及是否有数据

${item} 有两种用法,${item} 和 #{item},使用#号,会在生成sql的时候自动用占位符占位。


<select id="getUsers" resultMap="UserMap">
    select
    tm.team_id, u.uid, u.real_name name, tm.member_type, tm.create_time,tm.member_number,u.avatar,u.position,t.name team_name,t.city_name
    from lop_team_member tm left join user_info u on tm.uid = u.uid LEFT JOIN lop_team t ON tm.team_id = t.team_id
    <where>
        <if test="teamMember.teamId != null">
            and tm.team_id = #{teamMember.teamId,jdbcType=BIGINT}
        </if>
        <if test="teamMember.name != null">
            and u.real_name = #{teamMember.name,jdbcType=VARCHAR}
        </if>
        <if test="teamIds != null and teamIds.size() > 0">
          and tm.team_id not in
          <foreach collection="teamIds" index="index" item="item" open="(" separator="," close=")">
            ${item}
          </foreach>
        </if>
        and u.phone is null
    </where>
</select>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值