mybatis Mapper下insert和insertSelective的区别

insert(所有字段全部插入)

 <insert id="insert" parameterType="org.share.domain.dao.info.Address">
    insert into address (idaddress, name, add, 
      create_time, ts, iduser, phoneno
      )
    values (#{idaddress,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{add,jdbcType=VARCHAR}, 
      #{createTime,jdbcType=DATE}, #{ts,jdbcType=DATE}, #{iduser,jdbcType=VARCHAR}, #{phoneno,jdbcType=VARCHAR}
      )
  </insert>

insertselective(不为null字段全部插入)

<insert id="insertSelective" parameterType="org.share.domain.dao.info.Address">
    insert into address
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="idaddress != null">
        idaddress,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="add != null">
        add,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="ts != null">
        ts,
      </if>
      <if test="iduser != null">
        iduser,
      </if>
      <if test="phoneno != null">
        phoneno,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="idaddress != null">
        #{idaddress,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="add != null">
        #{add,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=DATE},
      </if>
      <if test="ts != null">
        #{ts,jdbcType=DATE},
      </if>
      <if test="iduser != null">
        #{iduser,jdbcType=VARCHAR},
      </if>
      <if test="phoneno != null">
        #{phoneno,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>

猜你喜欢

转载自blog.csdn.net/ppwwp/article/details/80733676
今日推荐