Mybatis ResultMap, mybatisresultmap

Source: Internet
Author: User

Mybatis ResultMap, mybatisresultmap

When you write complex ing statements, or the database column names and object names cannot be mapped, You need to configure a resing by using ResultMap.

It is also said on the official website that such a statement simply acts on keys automatically mapped to HashMap for all columns, which is specified by the resultType attribute. This is useful in many cases, but HashMap cannot describe a domain model well. In this way, your application will use JavaBeans or POJOs (Plain Old Java Objects, a common Java object) as the domain model. MyBatis supports both.

ResultMap is required when the column name is not correct or complex.

Specific Configuration:

<Mapper namespace = "com. huawei. dao. personMapper "> <resultMap id =" userResultMap "type =" Person "> <id property =" id "column =" id "/> <result property =" name "column =" name "/> <result property =" age "column =" age "/> </resultMap> <! -- Query all persons --> <select id = "queryAll" resultMap = "userResultMap"> select * from person where id =$ {1} </select> <insert id = "addTest "parameterType =" Person "flushCache =" true "> insert into 'person '('id ', 'name', 'age') VALUES (# {id}, # {name}, # {age}); </insert> </mapper>

Configure a ResultMap tag and set the id and ing object and column name and ing object fields

In the following example, use resultMap to call the API.

 

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.