Java-int type: int defaults to 0 to cause the update operation to update to 0 without assigning a value

Source: Internet
Author: User

In daily development, the process of doing the update operation is: When the field has a value is updated, no value is not updated, in the MyBatis XML is represented as:

<!--Modify a record to modify only fields that are not empty -    <UpdateID= "Updatebyselective"ParameterType= "Object" >Update Tb_mj_user Set<TrimSuffixoverrides="," >        <offTest= "sort!= null" >Sort=#{sort},</if>         <ifTest= "Updateby! = null" >Update_by=#{updateby},</if>         <ifTest= "Updatedate! = null" >Update_date=#{updatedate},</if>         <ifTest= "Delflag! = null" >Del_flag = #{delflag},</if>         </Trim>WHERE id = #{id}</Update>    

When the sort field is of type int, we do the update even if we do not set a value for sort, and the sort is updated to 0 when we finish the updatebyselective operation.

The reason for this is that int is one of the original data types in Java that provides 8, and the default value is 0, which cannot be expressed without assigning a value. At this point, we can define the sort as an integer type, the default null for integers, the ability to differentiate between unassigned cases, and the limitations of updatebyselective operations, which are updated when not empty.

Java-int type: int defaults to 0 to cause the update operation to update to 0 without assigning a value

Related Article

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.