ibatis中动态SQL_update

原创
2014/08/01 13:13
阅读数 1.8K

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


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

<isNotEmpty property="realName" prepend=","><![CDATA[ REALNAME = #realName# ]]></isNotEmpty>

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

<update id="updateRole" parameterClass="com.mmblue.model.Role">
	<![CDATA[
		UPDATE role
		SET
			gmt_modified = to_date(#gmtModified#,'yyyy-mm-dd hh24:mi:ss'),
			modifier = #modifier#
	]]>
		<dynamic>
			<isNotEmpty property="isDeleted" prepend=",">
				<![CDATA[
					is_deleted = #isDeleted#
				]]>
			</isNotEmpty>
			<isNotEmpty property="roleCode" prepend=",">
				<![CDATA[ 
					role_code = #roleCode#
				]]>
			</isNotEmpty>
			<isNotEmpty property="roleName" prepend=",">
				<![CDATA[ 
					role_name = #roleName#
				]]>
			</isNotEmpty>
			<isNotEmpty property="deptId" prepend=",">
				<![CDATA[ 
					dept_id = #deptId#
				]]>
			</isNotEmpty>
		</dynamic>
	<![CDATA[
		WHERE id = #id#
	]]>
</update>

 

 

2.再来个全部遍历的

<update id="updateUser" parameterClass="com.mmblue.domain.User">
		UPDATE MYIVR_TUSER
		<dynamic prepend="SET ">
					<isNotEmpty property="realName" prepend=","><![CDATA[ REALNAME = #realName# ]]></isNotEmpty>
					<isNotEmpty property="password" prepend=","><![CDATA[ PASSWORD = #password# ]]></isNotEmpty>
					<isNotEmpty property="projectId" prepend=","><![CDATA[ PROJECT_ID = #projectId# ]]></isNotEmpty>
					<isNotEmpty property="isEable" prepend=","><![CDATA[ ISENABLE = #isEable# ]]></isNotEmpty>
					<isNotEmpty property="createTime" prepend=","><![CDATA[ CREATETIME = #createTime# ]]></isNotEmpty>
					<isNotEmpty property="name" prepend=","><![CDATA[ USERNAME = #name# ]]></isNotEmpty>
					<isNotEmpty property="id" prepend=","><![CDATA[ USERID = #id# ]]></isNotEmpty>
					<isNotEmpty property="isFirstLogin" prepend=","><![CDATA[ ISFIRSTLOGIN = #isFirstLogin# ]]></isNotEmpty>
		</dynamic>
		<dynamic prepend="WHERE">
			USERID = #id#
		</dynamic>
	</update>
展开阅读全文
打赏
0
0 收藏
分享
加载中
推荐国内最流行的ibatis代码生成网站 --- fwjava.com
无需任何安装配置,直接在线生成,且十分规范好用.
现在,很多知名的互联网公司都在用它.
2016/09/20 19:24
回复
举报
更多评论
打赏
1 评论
0 收藏
0
分享
返回顶部
顶部