ibatis中动态SQL_update
如何知道上⼀篇的动态INSERT的话,动态UPDATE就很简单了,直接上XML
注意:如果<isNotEmpty>是写在⼀⾏的话,并且是第⼀个的话
<isNotEmpty property="realName" prepend=","><![CDATA[ REALNAME = #realName# ]]></isNotEmpty>内容注意中间加个空格,不然会出现 update role setname=xxx 直接报错
Xml代码
1. <update id="updateRole"parameterClass="del.Role">
2. <![CDATA[
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. <![CDATA[
11. is_deleted = #isDeleted#
12. ]]>
13. </isNotEmpty>
14. <isNotEmpty property="roleCode"prepend=",">
15. <![CDATA[
16. role_code = #roleCode#
17. ]]>
18. </isNotEmpty>
19. <isNotEmpty property="roleName"prepend=",">
20. <![CDATA[
21. role_name = #roleName#
22. ]]>
23. </isNotEmpty>
24. <isNotEmpty property="deptId"prepend=",">
25. <![CDATA[
26. dept_id = #deptId#
27. ]]>
28. </isNotEmpty>
29. </dynamic>
30. <![CDATA[
31. WHERE id = #id#
32. ]]>
33. </update>
2.再来个全部遍历的
Xml代码
1. <update id="updateUser"parameterClass="blue.domain.User">
2. UPDATE MYIVR_TUSER
3. <dynamic prepend="SET ">
4. <isNotEmpty property="realName"prepend=","><![CDATA[ REALNAME = #realName# ]]></isNotEmpty>
5. <isNotEmpty property="password"prepend=","><![CDATA[ PASSWORD = #password# ]]></isNotEmpty>
6. <isNotEmpty property="projectId"prepend=","><![CDATA[ PROJECT_ID = #projectId# ]]></isNotEmpty>
7. <isNotEmpty property="isEable"prepend=","><![CDATA[ ISENABLE = #isEable# ]]></isNotEmpty>
8. <isNotEmpty property="createTime"prepend=","><![CDATA[ CREATETIME = #createTime# ]]></isNotEm
pty>
9. <isNotEmpty property="name"prepend=","><![CDATA[ USERNAME = #name# ]]></isNotEmpty>
10. <isNotEmpty property="id"prepend=","><![CDATA[ USERID = #id# ]]></isNotEmpty>
11. <isNotEmpty property="isFirstLogin"prepend=","><![CDATA[ ISFIRSTLOGIN = #isFirstLogin# ]]></isNotE
mpty>
12. </dynamic>
13. <dynamic prepend="WHERE">
sql中update什么意思14. USERID = #id#
15. </dynamic>
16. </update>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论