Resulttype and Resultmap in the MyBatis

Source: Internet
Author: User

MyBatis queries are mapped, the return value type can use Resulttype and resultmap can also be used. The former refers to the direct return value type, usually the domain name, of course, here can write all the path of domain can also be abbreviated so that you have to scan the entity in the MyBatis configuration file. While the latter represents a reference to an external resultmap, both cannot exist at the same time.

MyBatis in the query mapping, in fact, and JdbcTemplate in the same queryforlist is the query out of each attribute is placed in a corresponding map, where the key is the property name, the value is the corresponding value.

When we provide a return type of Resulttype, MyBatis will remove the key value pair from the map to the property assigned to the object specified by Resulttype, so the return type of each query map MyBatis is resultmap. Just when the return type we provide is Resulttype, MyBatis automatically assigns the corresponding value to the property of the object specified by Resulttype.

When the return type we provide is resultmap, because map does not represent the domain model well, we need to define our own mapping of the Resultmap and domain model to further convert it to the corresponding object.

<!--Seckill Querybyid (long seckillid);-->
<select id= "Querybyid" parametertype= "Long" resulttype= "Seckill" >
Select Seckill_id,name,number,start_time,end_time,create_time
From Seckill
where seckill_id = #{seckillid}
</select>

MyBatis automatically creates a Resultmap object because Resulttype is specified here, so it is removed from the Resultmap and assigned to the corresponding key value in the Seckill object.

Follow-up introduction then write ~ work

Resulttype and Resultmap in the MyBatis

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.