mybatis provided when adding new object data type id automatically written to the database using uuid

Add the following code marked red insert mapper.xml file id achieved by way of self written to the database, and to write a character uuid

<insert id="insert" parameterType="ssm.item.admin.bean.Depart" useGeneratedKeys="true" keyProperty="departId">
      <selectKey keyProperty="departId" resultType="java.lang.String"
    order="BEFORE">
    select replace(uuid(),'-','') from dual
    </selectKey>
    insert into depart (depart_id, depart_name, depart_code
      )
    values (#{departId,jdbcType=VARCHAR}, #{departName,jdbcType=VARCHAR}, #{departCode,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="ssm.item.admin.bean.Depart" useGeneratedKeys="true" keyProperty="departId">
      <selectKey keyProperty="departId" resultType="java.lang.String"
    order="BEFORE">
    select replace(uuid(),'-','') from dual
    </selectKey>
    insert into depart
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="departId != null">
        depart_id,
      </if>
      <if test="departName != null">
        depart_name,
      </if>
      <if test="departCode != null">
        depart_code,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="departId != null">
        #{departId,jdbcType=VARCHAR},
      </if>
      <if test="departName != null">
        #{departName,jdbcType=VARCHAR},
      </if>
      <if test="departCode != null">
        #{departCode,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>

 

Guess you like

Origin www.cnblogs.com/xiaoqilaile/p/10951451.html