MyBatis 中的 set 元素用法(MyBatis 3.1.1)

现在的写法(A)

 1     <update id="update" parameterType="ruleItem.Bean">
 2         update t_rule_item
 3         <!-- set id=#{id} --> 
 4         <set>
 5             <if test="ruleId!=null and ruleId != ''">ruleId=#{ruleId},</if>
 6             <if test="fieldName!=null and fieldName != ''">fieldName=#{fieldName},</if>
 7             <if test="comment!=null and comment != ''">comment=#{comment},</if>        
 8         </set>
 9         where id=#{id}
10     </update>

 原来的写法(B)

 1     <update id="update" parameterType="ruleItem.Bean">
 2         update t_rule_item
 3         set id=#{id}
 4         
 5             <if test="ruleId!=null and ruleId != ''">,ruleId=#{ruleId}</if>
 6             <if test="fieldName!=null and fieldName != ''">,fieldName=#{fieldName}</if>
 7             <if test="comment!=null and comment != ''">,comment=#{comment}</if>        
 8         
 9         where id=#{id}
10     </update>

区别:(B)的第三行,以及“,”(逗号的位置)。

 

posted on 2013-07-25 09:17  Livon  阅读(1322)  评论(0编辑  收藏  举报

导航