ResultMap and differences

<resultMap type="com.wkd.entity.AreaCode" id="baseResultMap">
		<!-- colum:表中列名(大写) property:类中属性名 jdbcType:表中类型 -->
		<id column="CODE" property="code" jdbcType="VARCHAR" />
		<result column="CONTENT" property="content" jdbcType="VARCHAR" />
		<result column="CODE_LEVEL" property="code_level" jdbcType="CHAR" />
		<result column="SUPERIOR" property="superior" jdbcType="VARCHAR" />
</resultMap>

1, resultMap element defines a com.wkd.entity.AreaCode (fully qualified name here), its id attribute representative of its identification, the class type used as representative of the class which is mapped, may be an alias or the fully qualified name . ↓↓↓

<resultMap type="com.wkd.entity.AreaCode" id="baseResultMap">

Representative sub-elements resultMap id primary key, and the result on behalf of its properties.


2, in the first resultMap custom columns are typically primary key id, id and result then what difference does it?
id and result values are mapped to a single attribute or a simple data type field.
The only difference is that, as id is uniquely identified, and when the other object instances contrast, the id is useful, especially applied to the results of the mapping cache and embedded.


3, property: the mapping database column field or property, if JavaBean properties match the given name will be used to match the name to the search field or MyBatis given name, in both cases you can use a comma the property forms, for example, you can map to "" username :, can be mapped to "address.street.number"


4, column: column name or database alias column labels, and passed a resultSet.getString (columnName) parameters the same name.


5, following two I do not understand, it may be used after the first presence here says ...
the javaType: complete java class name or an alias, if mapped to a JavaBean, then MyBatis usually self monitored. However, if mapped to a HashMap, it should be clearly specified javaType to ensure the desired behavior.
jdbcType; jdbc type of support, this property allows only empty columns is useful for, JDBC needs in this insert, update, delete the time, but Mybatis not, if the direct write JDBC code, in case of need to allow null values specify the type.
Here Insert Picture Description

See detailed understanding of this article: the mybatis in understanding resultMap

Published 53 original articles · won praise 60 · views 4940

Guess you like

Origin blog.csdn.net/qq_37717494/article/details/104648275