Ibatis & lt; dynamic & gt; tag update Summary

Source: Internet
Author: User

1. in order TO use <dynamic>'s <isNotNull> and other places TO encounter unnecessary bugs, we define all types as original types when defining map or TO, such as defining INTEGER.

2. when writing a statement, it is easy to introduce difficult errors such as ":", and ":". the two characters are in. the differences in java files are obvious, but they cannot be seen by the naked eye in xml. Therefore, use punctuation in half-width English.

3. Define the type as accurately as possible for all fields that appear. Although it seems that writing or not writing can run normally in some places, this can reduce the chance of errors and reduce the worries.

4. paste an example.

TOMap:
[Html]
<ResultMap id = "userTO" class = "UserTO">
<! -- Set the correspondence between the required data table items and UserTO member variables -->
<Result column = "ID" jdbcType = "int" javaType = "java. lang. Integer" property = "id"/>
<Result column = "USERNAME" jdbcType = "varchar" javaType = "java. lang. String" property = "username"/>
<Result column = "PASSWORD" jdbcType = "varchar" javaType = "java. lang. String" property = "password"/>
<Result column = "GENDER" jdbcType = "Integer" javaType = "java. lang. Integer" property = "gender"/>
<Result column = "DATE_OF_BIRTH" jdbcType = "date" javaType = "java. util. Date" property = "dateOfBirth"/>
<Result column = "CREATED_DATE" jdbcType = "datetime" javaType = "java. util. Date" property = "createdDate"/>
<Result column = "IMAGE_ID" jdbcType = "Integer" javaType = "java. lang. Integer" property = "imageId"/>
</ResultMap>

SQL:

[Html]
<Update id = "updateUserinfoById" parameterClass = "UserTO">
Update USER
<Dynamic prepend = "set">
<IsNotNull prepend = "," property = "password"> PASSWORD = # password: VARCHAR # </isNotNull>
<IsNotNull prepend = "," property = "gender"> GENDER = # gender: INTEGER # </isNotNull>
<IsNotNull prepend = "," property = "dateOfBirth"> DATE_OF_BIRTH = # dateOfBirth: TIMESTAMP # </isNotNull>
<IsNotNull prepend = "," property = "imageId"> IMAGE_ID = # imageId: INTEGER # </isNotNull>
<IsNotNull prepend = "," property = "status"> STATUS = # status: INTEGER # </isNotNull>
</Dynamic>
Where ID = # id: INTEGER #
</Update>

TO:
[Html]
Public class UserTO implements Constant {
 
Private Integer id;
 
Private String username;
 
Private String password;
 
Private Integer gender;
 
Private Integer imageId;
 
Private Date dateOfBirth;
 
Private Date createdDate;

If you can, you can perform two sets of TO, one as the parameter, and the other as the return value. Here is not an example.

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.