Mybatis dynamic SQL tag

1. trim label

  A. trim tab is generally used to remove excess sql statement and key, comma, or prior to splicing sql statement "where", "set" and "values ​​(" et prefix, or add ")" suffix, can be used selectively insert, update, or delete information, operation condition;

  B. tag attributes

Attributes description
prefix
Sql statement to prefix stitching
prefixOverrides

Remove the front of the sql statement keywords or characters, the character or keyword is specified by prefixesToOverride property, assuming the property is designated as "AND", when sql statement beginning with "AND", trim tab will remove the "AND"
suffix
Suffix sql statement to mosaic
suffixOverrides
Removing keywords or characters following sql statement, the keyword or character attributes specified by the suffixesToOverride

  C. Examples 

<insert id="insertSelective" parameterType="com.ruhuanxingyun.Manufacture" >
    insert into manufacture
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="productType != null" >
        product_type,
      </if>
      <if test="sdkNum != null" >
        sdk_num,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=BIGINT},
      </if>
      <if test="productType != null" >
        #{productType,jdbcType=VARCHAR},
      </if>
      <if test="sdkNum != null" >
        #{sdkNum,jdbcType=CHAR},
      </if>
      <if test="deviceType != null" >
        #{deviceType,jdbcType=BIT},
      </if>
    </trim>
  </insert>

 

Guess you like

Origin www.cnblogs.com/ruhuanxingyun/p/10942247.html