mybatis传参接收问题

mybatis传参接收问题

单个参数且为基础类型

mapper文件中

    User findByEmail(String email);

mapper.xml中

        <select id="findByEmail" resultMap="BaseResultMap"
            parameterType="java.lang.String">
        select
        <include refid="BaseColumns"/>
        ,d.dept_name,d.dept_type
        from sys_user t
        left join sys_dept d on t.dept_id=d.dept_id
        where t.email = #{aaa} and t.del_flag = '0'
    </select>

总之 随便写都行

单个参数且为包装类型

mapper文件中

    int  checkLoginNameUnique(User user);

mapper.xml中

        
    <select id="checkLoginNameUnique" resultType="java.lang.Integer"
            parameterType="com.yss.base.model.user.User">
        select count(1)
        from sys_user t
        <where>
            t.del_flag = '0'
            <if test="userId !=null and userId !=''">
                and t.user_id != #{userId}
            </if>
            <if test="loginName !=null and loginName !=''">
                and t.login_name = #{loginName}
            </if>
        </where>
    </select>

直接写成员变量名

多个参数且为基础类型

mapper文件中

    void updateAvatar(@Param("userId") String userId, @Param("url") String url);

mapper.xml中

        
    update sys_user set avatar = #{url} where user_id = #{userId}

加上@Param(“xx”) 参数名需对应
或者
mapper文件中

    void updateAvatar( String userId, String url);

mapper.xml中(jdk1.7)

        
    update sys_user set avatar = #{1} where user_id = #{0}

mapper.xml中(jdk1.8)

        
    update sys_user set avatar = #{param1} where user_id = #{param0}

mapper.xml中(jdk1.8也可以)

        
    update sys_user set avatar = #{arg1} where user_id = #{arg0}

多个参数且为封装类型

mapper文件中

    List<User> getMyDeptUser(Page<User> page, @Param("bean") User user);

mapper.xml中

        
    <select id="getMyDeptUser"
            parameterType="com.yss.base.model.user.User" resultMap="BaseResultMap">
        select
        <include refid="BaseColumns"/>
        ,d.dept_name
        from sys_user t
        left join sys_dept d on t.dept_id=d.dept_id
        <where>
            t.del_flag = '0'
            <if test="bean.userId !=null and bean.userId !=''">
                and t.user_id != #{bean.userId}
            </if>
            <if test="bean.username !=null and bean.username !=''">
                and t.username like
                <if test="_databaseId == 'oracle'">'%'||#{bean.username}||'%'</if>
                <if test="_databaseId == 'mssql'">'%'+#{bean.username}+'%'</if>
                <if test="_databaseId == 'mysql'">concat('%',#{bean.username},'%')</if>
            </if>
            <if test="bean.loginName !=null and bean.loginName !=''">
                and t.login_name like
                <if test="_databaseId == 'oracle'">'%'||#{bean.loginName}||'%'</if>
                <if test="_databaseId == 'mssql'">'%'+#{bean.loginName}+'%'</if>
                <if test="_databaseId == 'mysql'">concat('%',#{bean.loginName},'%')</if>
            </if>
            <if test="bean.email !=null and bean.email !=''">
                and t.email like
                <if test="_databaseId == 'oracle'">'%'||#{bean.email}||'%'</if>
                <if test="_databaseId == 'mssql'">'%'+#{bean.email}+'%'</if>
                <if test="_databaseId == 'mysql'">concat('%',#{bean.email},'%')</if>
            </if>
            <if test="bean.deptId !=null and bean.deptId !=''">
                and t.dept_id=#{bean.deptId}
            </if>
            <if test="bean.deptIds !=null and bean.deptIds.size()>0 ">
                and t.dept_id in
                <foreach collection="bean.deptIds" item="item" index="index"
                         open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
        order by t.crt_time desc
    </select>

加上@Param(“xx”) 参数名需对应

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值