区别:
- isNotNull:表示参数不为NULL,返回TRUE反之则为FALSE
- isNull:表示参数为NULL,返回TRUE反之则为FALSE
- isNotEmpty:表示参数不为NULL也不为空,返回TRUE反之则返回FALSE
- isEmpty:表示参数为NULL或着为空,返回TRUE反之则为FALSE
例:当xml代码中用isNotEmpty配置时<select id="queryTable" resultClass="int" parameterClass="QryCondition"> select count(id) from table <dynamic prepend="WHERE"> <isNotEmpty prepend="AND" property="abc"> ( table.filed1 LIKE '%$abc$%') </isNotEmpty> <isNotEmpty prepend="AND" property="def"> ( table.filed2 LIKE '%$def$%') </isNotEmpty> </dynamic> </select>
当之传入参数 abc 而不传入 def 时,产生的SQL语句为:
select count(id) from table where(table.filed1 LIKE '%abc%');
当XML代码中用isNotNull配置时(注意他们的区别):
<select id="queryTable" resultClass="int" parameterClass="QryCondition"> select count(id) from table <dynamic prepend="WHERE"> <isNotNull prepend="AND" property="abc"> (table.field1 LIKE '%$abc$%') </isNotNull> <isNotNull prepend="AND" property="def"> (table.field2 LIKE '%$def$%') </isNotNull> </dynamic> </select>
同样 ,当传入参数 abc 而不传入 def 时,产生的SQL语句为:
select count(id) from table where (table.field1 LIKE '%abc%') AND (table.field2 LIKE '%%')
注意:
必须使用ISNULL()来判断是否为NULL值。
说明:NULL与任何值的直接比较都为NULL。
1) NULL<>NULL的返回结果是NULL,而不是false。
2) NULL=NULL的返回结果是NULL,而不是true。
3) NULL<>1的返回结果是NULL,而不是true。
转载于:https://blog.51cto.com/13890766/2352074