插入语句的xml小结

2019-03-18  本文已影响0人  轰轰_9ccd

<update id="updateByPrimaryKey" parameterType="com.glxcn.mybatis.model.TSysUser">

  update t_sys_user

<trim prefix="set" suffixOverrides=",">

    <if test="username!=null">

      username = #{username,jdbcType=VARCHAR},

    <if test="password!=null and password!=''">

      password = #{password,jdbcType=VARCHAR},

    <if test="createTime!=null">

      create_time = #{createTime,jdbcType=TIMESTAMP},

    <if test="salt!=null">

      salt = #{salt,jdbcType=VARCHAR},

    <if test="loginTime!=null">

      login_time = #{loginTime,jdbcType=TIMESTAMP},

    <if test="logoutTime!=null">

      logout_time = #{logoutTime,jdbcType=TIMESTAMP},

    <if test="lastIp!=null">

      last_ip = #{lastIp,jdbcType=VARCHAR},

    <if test="status!=null">

      status = #{status,jdbcType=BIT},

    <if test="des!=null">

      des = #{des,jdbcType=VARCHAR},

    <if test="avatar!=null">

      avatar = #{avatar,jdbcType=VARCHAR},

    <if test="audit!=null">

      audit = #{audit,jdbcType=VARCHAR},

    <if test="ip!=null">

      ip = #{ip,jdbcType=VARCHAR},

    <if test="realname!=null">

      realname = #{realname,jdbcType=VARCHAR},

  where user_id = #{userId,jdbcType=INTEGER}

</update>

可以用 此方法进行判断

    


在注解上useGeneratedKeys="true" keyProperty="userId"加这个默认返回id;keyProperty为主键名称

上一篇 下一篇

猜你喜欢

热点阅读