Differences between isnotnull and isnotempty in ibatis

Source: Internet
Author: User

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?
  1. <Select id = "getcustomerregnum" resultclass = "int" parameterclass = "querycustomercondition">
  2. Select count (cus_id) from cus_customer_tbl
  3. <Dynamic prepend = "where">
  4. <Isnotempty prepend = "and" property = "cuswebfrom">
  5. (Cus_customer_tbl.cus_web_from like '% $ cuswebfrom $ % ')
  6. </Isnotempty>
  7. <Isnotempty prepend = "and" property = "cuswebagent">
  8. (Cus_customer_tbl.cus_web_agent like '% $ cuswebagent $ % ')
  9. </Isnotempty>
  10. </Dynamic>
  11. </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?
  1. <Select id = "getcustomerregnum" resultclass = "int" parameterclass = "querycustomercondition">
  2. Select count (cus_id) from cus_customer_tbl
  3. <Dynamic prepend = "where">
  4. <Isnotnull prepend = "and" property = "cuswebfrom">
  5. (Cus_customer_tbl.cus_web_from like '% $ cuswebfrom $ % ')
  6. </Isnotnull>
  7. <Isnotnull prepend = "and" property = "cuswebagent">
  8. (Cus_customer_tbl.cus_web_agent like '% $ cuswebagent $ % ')
  9. </Isnotnull>
  10. </Dynamic>
  11. </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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.