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