return type of MyBatis

Source: Internet
Author: User

The return parameter type of MyBatis is divided into two types

1. The corresponding classification is:

1.1.RESULTMAP:

1.2.resultType:


2. Corresponding return value type:

2.1.RESULTMAP: Result set

2.2.resulttype:int,string, Long, Class 3. Note the point:

In the MyBatis query mapping, in fact, each of the properties of the query is placed in a corresponding map inside, where the key is the property name, the value is its corresponding value.

3.1 When the provided return type property is Resulttype, MyBatis will remove the key-value pair from the map to the property assigned to the object specified by Resulttype. So actually the return type of each query map of MyBatis is Resultmap, only when the return type property provided is Resulttype
The MyBatis assigns the corresponding value to the property of the object specified by Resulttype.

3.2 When the return type provided is RESULTMAP, because map does not represent the domain model well, it needs to be further transformed into its corresponding object, which is often useful in complex queries.

4. Case Studies

4.1:resultmap Case

[HTML] view plain copy <select id= "Selectbyprimarykey" resultmap= "Baseresultmap" parametertype= "Java.lang . Long "> select <include refid=" Base_column_list "/> from common_car_make where id = #{id , jdbctype=bigint} </select> 4.2 Resulttype--long case

[HTML] view plain copy <select id= "Querycartypebymodelidcount" resulttype= "Java.lang.Long" parametertype= "Java.util.Map" > select COUNT (*) from common_car_type cm where 1=1 <if test= "Carmodel Id! = null "> and cm.car_model_id = #{carmodelid,jdbctype=decimal} </if> </selec t> 4.3 resulttype--int case

[HTML]   View plain  copy   <select id= "Querycategorybrandcount"   Resulttype= "Java.lang.Integer"  parametertype= "Java.util.HashMap"  >            select count (1)             from common_category_brand           where 1=1            <if test= "Categoryid != null"  >               and  Category_id = #{categoryid,jdbctype=bigint

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.