动态insert mybatis与ibatis

mybatis:

<insert id="insert" parameterType="hashMap">
    INSERT INTO item
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      ...
      </if>
      <if test="created != null">
        created,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=BIGINT},
      </if>
      ...
      <if test="created != null">
        #{created,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>

ibatis:

<insert id="insert" parameterClass="hashMap">
        INSERT INTO item
        <dynamic prepend="(" close=")">
            <isNotNull prepend="," property="obj.id">
                id
            </isNotNull>
            ...
            ,created
        </dynamic>
        VALUES
        <dynamic prepend="(" close=")">
            <isNotNull prepend="," property="obj.id">
                #obj.id#
            </isNotNull>
             ...
            ,now()
        </dynamic>
        <selectKey resultClass="long" keyProperty="id">
            SELECT LAST_INSERT_ID() AS ID
        </selectKey>
 </insert>
posted @ 2018-07-06 14:20  花拾夕  阅读(1062)  评论(0编辑  收藏  举报