When using mybatisResultmap
Compared with resultclass, resultmap can adapt to more complex link ing, and allows you to specify the Data Type of a field. It supports "select *" and does not require defining Mappings of all returned fields in the resultset.
Configure the following in resultmap:
<Resultmap id = "baseresultmap" type = "full path of the class"> <ID column = "Table ID column" property = "corresponding class attribute" jdbctype = "type of data inserted into the database "/> <result column =" other columns in the table "property =" "jdbctype =" "/>
/* If the class to be mapped contains objects as class attributes (the class contains other classes), use association in resultmap,
If collection is used for a collection (one-to-multiple), if column is used for collection, it is generally used with select */<association property = "projectorg" javatype = "com. ldrc. SRM. ou. dal. dataobject. projectinfo. project. projectorg "resultmap =" projectorgmapper. baseresultmap "> </association> <collection property =" rolelist "column =" us_id "oftype =" com. zjx. entity. system. role"
Resultmap = "rolemapper. baseresultmap" select = "rolemapper. selectuserroles">
</Collection> </resultmap>
Resultmap is the most common and important attribute. The value of the resultmap attribute is equal to the pre-defined resultmap element.
(See the following example ). Using resultmap can control how data is retrieved from the result set and which attribute matches which field. Unlike the automatic resing method of resultclass, The resultmap attribute allows you to specify the Data Type of a field, and the replacement value of null for complex type ing (including other Java Beans, set types, and basic type packaging classes ). The detailed discussion of the resultmap is described in a later chapter. Here we only provide an example of the resultmap of the relevant statement.
<Resultmap id = "get-product-result" class = "com. ibatis. example. Product">
<Result property = "ID" column = "prd_id"/>
<Result property = "Description" column = "prd_description"/>
</Resultmap>
<Statement id = "getproduct" resultmap = "get-product-result">
Select * from product
</Statement>
In the preceding example, with the resultmap definition, the resultset obtained by the query statement is mapped to the product pair.
Image. The "ID" attribute value defined by resultmap is assigned with the "pro_id" field value, and the "Description" attribute value is assigned with the "prd_description" field value. Note that resultmap supports "select *" and does not require the resing of all returned fields in the resultset.