ibatis中动态SQL_update

如何知道上一篇的动态INSERT的话,动态UPDATE就很简单了,直接上XML


注意:如果是写在一行的话,并且是第一个的话

内容注意中间加个空格,不然会出现 update role setname=xxx 直接报错

Xml代码   收藏代码
  1. <update id="updateRole" parameterClass="com.mmblue.model.Role">  
  2.      
  3.         UPDATE role 
  4.         SET 
  5.             gmt_modified = to_date(#gmtModified#,'yyyy-mm-dd hh24:mi:ss'), 
  6.             modifier = #modifier# 
  7.     ]]>  
  8.         <dynamic>  
  9.             <isNotEmpty property="isDeleted" prepend=",">  
  10.                  
  11.                     is_deleted = #isDeleted# 
  12.                 ]]>  
  13.             isNotEmpty>  
  14.             <isNotEmpty property="roleCode" prepend=",">  
  15.                  
  16.                     role_code = #roleCode# 
  17.                 ]]>  
  18.             isNotEmpty>  
  19.             <isNotEmpty property="roleName" prepend=",">  
  20.                  
  21.                     role_name = #roleName# 
  22.                 ]]>  
  23.             isNotEmpty>  
  24.             <isNotEmpty property="deptId" prepend=",">  
  25.                  
  26.                     dept_id = #deptId# 
  27.                 ]]>  
  28.             isNotEmpty>  
  29.         dynamic>  
  30.      
  31.         WHERE id = #id# 
  32.     ]]>  
  33. update>  

 

 

2.再来个全部遍历的

Xml代码   收藏代码
  1. <update id="updateUser" parameterClass="com.mmblue.domain.User">  
  2.     UPDATE MYIVR_TUSER  
  3.     <dynamic prepend="SET ">  
  4.                 <isNotEmpty property="realName" prepend=",">isNotEmpty>  
  5.                 <isNotEmpty property="password" prepend=",">isNotEmpty>  
  6.                 <isNotEmpty property="projectId" prepend=",">isNotEmpty>  
  7.                 <isNotEmpty property="isEable" prepend=",">isNotEmpty>  
  8.                 <isNotEmpty property="createTime" prepend=",">isNotEmpty>  
  9.                 <isNotEmpty property="name" prepend=",">isNotEmpty>  
  10.                 <isNotEmpty property="id" prepend=",">isNotEmpty>  
  11.                 <isNotEmpty property="isFirstLogin" prepend=",">isNotEmpty>  
  12.     dynamic>  
  13.     <dynamic prepend="WHERE">  
  14.         USERID = #id#  
  15.     dynamic>  
  16. update>  

你可能感兴趣的:(Ibatis)