1:
在iBATIS中isNull用于判断参数是否为Null,isNotNull相反
isEmpty判断参数是否为Null或者空,满足其中一个条件则其true
isNotEmpty相反,当参数既不为Null也不为空是其为true
判断之后做相对应的表达式操作
2:用isNotNull估计老有问题,Stirng类型最后用isNotEmpty
<dynamic prepend="where"> <isNotNull prepend=" and " property="id">U.ID = #id:INTEGER#</isNotNull> <isNotNull prepend=" and " property="deptId">U.DEPT_ID = #deptId:INTEGER#</isNotNull> <isNotEmpty prepend=" and " property="email">U.EMAIL = #email:VARCHAR#</isNotEmpty> <isNotEmpty prepend=" and " property="name">U.NAME = #name:VARCHAR#</isNotEmpty> </dynamic>
3:
更新的动态写法
<update id="update" parameterClass="UserCriteriaTO"> update USER <dynamic prepend="set"> <isNotNull prepend="," property="deptId">DEPT_ID = #deptId:INTEGER#</isNotNull> <isNotNull prepend="," property="email">EMAIL = #email:VARCHAR#</isNotNull> <isNotNull prepend="," property="name">NAME = #name:VARCHAR#</isNotNull> <isNotNull prepend="," property="password">PASSWORD = #password:VARCHAR#</isNotNull> <isNotNull prepend="," property="headImg">HEAD_IMG = #headImg:VARCHAR#</isNotNull> <isNotNull prepend="," property="createdDate">CREATED_DATE = #createdDate:DATETIME#</isNotNull> <isNotNull prepend="," property="status">STATUS = #status:INTEGER#</isNotNull> </dynamic> where id = #id:INTEGER# </update> 注意 一定不要写 and 是用,号分割,并且不能有空格