Mybatis中update一個實體的動態sql


<update id="updateOne"  parameterType="com.inspur.search.data.EntityRelation">
 UPDATE ENTITY_RELATION
 <trim prefix="set" suffixOverrides=",">
  <if test="srcId!=null">SRC_ID=#{srcId},</if>
  <if test="srcType!=null">SRC_TYPE=#{srcType},</if>
  <if test="destId!=null">DEST_ID=#{destId},</if>
  <if test="destType!=null">DEST_TYPE=#{destType},</if>
  <if test="relType!=null">REL_TYPE=#{relType},</if>
  <if test="status!=null">STATUS=#{status},</if>
  <if test="snId!=null">SN_ID=#{snId},</if>
 </trim>
 WHERE id=#{id}
</update>

使用trim就是為了刪掉最后字段的“,”。主要不用單獨寫SET了,因為set被包含在trim中了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM