Unary tags examine the state of a bean property and do not perform comparisons
Against any other values. The body content is wrongly ded if the result of the state is
True. All unary tags share the property attribute. The property attribute is used
Specify the property on the parameter object that will be used to examine
State. The name of the tag indicates the type of State that is being examined.
Unary tag attributes are shown in Table 8.4.
All of the attributes in Table 8.4 are available in the unary dynamic SQL tags listed
In table 8.5.
Table 8.4 unary tag attributes
Property
(Required)
The property of the parameter used for state comparison.
Prepend
(Optional)
This value is used to prepend to the tag's resulting body content. The prepend
Value will not be prepended (a) when the tag's resulting body content is empty; (B) if
The tag is the first to produce body content and is nested in a tag with the remove-
Firstprepend attribute set to true; or (c) if the tag is the first to produce body content
Following a <dynamic> tag with a prepend attribute value that is not empty.
Open
(Optional)
This value is used to prefix to the tag's resulting body content. The open value will
Not be prefixed if the tag's resulting body content is empty. The open value is prefixed
Before the prepend attribute's value is prefixed. For example, if prepend = "or
"And open =" (", then the resulting combined prefix wocould be" or (".
Close
(Optional)
This value is used to append to the tag's resulting body content. The append Value
Will not be appended if the tag's resulting body content is empty.
Removefirst-
Prepend
(Optional)
This attribute value defines whether the first nested content-producing tag will have
Its prepend value removed.
Table 8.5 unary tags
<Isproperty-
Available>
Determines whether the specified property exists in the parameter. With
Bean, it looks for a property. With a map, it looks for a key.
<Isnotproperty-
Available>
Checks whether the specified property does not exist in the parameter.
A bean, it looks for a property. With a map, it looks for a key.
<Isnull> determines whether the specified property is null. With a bean, it looks
The value of the property getter. With a map, it looks for a key. If the key
Does not exist, it will return true.
<Isnotnull> determines whether the specified property is anything other than Null.
A bean, it looks at the value of the property getter. With a map, it looks for
Key. If the key does not exist, it will return false.
<Isempty> determines whether the specified property is a null or empty string, collection,
Or string. valueof ().
<Isnotempty> determines whether the specified property is not a null or empty string,
Collection, or string. valueof ().
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------------
In ibatis, isnull is used to determine whether the parameter is null. isnotnull is opposite.
Isempty checks whether the parameter is null or null. If one of the conditions is met, its true isnotempty is opposite. If the parameter is neither null nor empty, it is true.
Perform corresponding expression operations after judgment
The following code:
[HTML]View plaincopyprint?
- <Select id = "getcustomerregnum" resultclass = "int" parameterclass = "querycustomercondition">
- Select count (cus_id) from cus_customer_tbl
- <Dynamic prepend = "where">
- <Isnotempty prepend = "and" property = "cuswebfrom">
- (Cus_customer_tbl.cus_web_from like '% $ cuswebfrom $ % ')
- </Isnotempty>
- <Isnotempty prepend = "and" property = "cuswebagent">
- (Cus_customer_tbl.cus_web_agent like '% $ cuswebagent $ % ')
- </Isnotempty>
- </Dynamic>
- </SELECT>
<select id="getCustomerRegNum" resultClass="int" parameterClass="QueryCustomerCondition"> select count(cus_id) from cus_customer_tbl <dynamic prepend="WHERE"> <isNotEmpty prepend="AND" property="cusWebFrom"> ( CUS_CUSTOMER_TBL.CUS_WEB_FROM LIKE ‘%$cusWebFrom$%‘) </isNotEmpty> <isNotEmpty prepend="AND" property="cusWebAgent"> ( CUS_CUSTOMER_TBL.CUS_WEB_AGENT LIKE ‘%$cusWebAgent$%‘) </isNotEmpty> </dynamic> </select>
When the input parameter cuswebform is not passed inThe SQL statement generated when cuswebagent is:
Select count (cus_id) from cus_customer_tbl where (cus_customer_tbl.cus_web_from like '% Baidu % ')
When the XML code is configured with <isnotnull> (pay attention to their differences ),
[HTML]View plaincopyprint?
- <Select id = "getcustomerregnum" resultclass = "int" parameterclass = "querycustomercondition">
- Select count (cus_id) from cus_customer_tbl
- <Dynamic prepend = "where">
- <Isnotnull prepend = "and" property = "cuswebfrom">
- (Cus_customer_tbl.cus_web_from like '% $ cuswebfrom $ % ')
- </Isnotnull>
- <Isnotnull prepend = "and" property = "cuswebagent">
- (Cus_customer_tbl.cus_web_agent like '% $ cuswebagent $ % ')
- </Isnotnull>
- </Dynamic>
- </SELECT>
<select id="getCustomerRegNum" resultClass="int" parameterClass="QueryCustomerCondition"> select count(cus_id) from cus_customer_tbl <dynamic prepend="WHERE"> <isNotNull prepend="AND" property="cusWebFrom"> ( CUS_CUSTOMER_TBL.CUS_WEB_FROM LIKE ‘%$cusWebFrom$%‘) </isNotNull> <isNotNull prepend="AND" property="cusWebAgent"> ( CUS_CUSTOMER_TBL.CUS_WEB_AGENT LIKE ‘%$cusWebAgent$%‘) </isNotNull> </dynamic> </select>
Similarly, when the parameter cuswebform is passed inThe SQL statement generated when cuswebagent is:
Select count (cus_id) from cus_customer_tbl where (cus_customer_tbl.cus_web_from like '% Baidu %') and (cus_customer_tbl.cus_web_agent like '% ')
The difference between SQL statements .....
Differences between isnotnull and isnotempty in ibatis