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.