Mybatis SQL mapping File

Source: Internet
Author: User

Simple query

Insert Add

Insert can use the automatically generated primary key policy supported by the database, set usegeneratedkeys= "true", and then set the Keyproperty to the corresponding column, it is done. For example, the studententity above uses auto-generated to generate a primary key for the ID column.
You can also use the Selectkey element. In the following example, use MySQL database nextval (' student ') as a custom function to generate a key.

Update modification

The SQL element is used to define a reusable SQL statement segment that can be called by other statements. Like what:

The difference between Resulttype and Resultmap

1, Resulttype

Return a single instance

<select id= "Selectuser" parametertype= "int" resulttype= "User" >

SELECT * from user where id = #{id}

</select>
Returns the list collection

<select id= "Selectuserall" resulttype= "User" > <!--resultmap= "UserMap"-
SELECT * FROM user
</select>

2, Resultmap

Simple query:

<resultmap type= "User" id= "UserMap" >
<id column= "id" property= "id"/>
<result column= "name" property= "name"/>
</resultMap>
Column: Name in database, property: attribute name in class

Resultmap: The case of a custom entity class that is suitable for using return values

Resulttype: Suitable for use return-worthy data types are non-customizable, that is, the supplied type of JDK

Resultmap:

Mapping the data type of an entity class

Unique identification of the RESULTMAP

Column: Field name of the library table

Property: The attribute name in the entity class

Mybatis SQL mapping File

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.