Mybatis:resultMap usage summary

Elements contained in resultMap:

<!--column不做限制,可以为任意表的字段,而property须为type 定义的pojo属性-->
<resultMap id="唯一的标识" type="映射的pojo对象">
  <id column="表的主键字段,或者可以为查询语句中的别名字段" jdbcType="字段类型" property="映射pojo对象的主键属性" />
  <!-- result就是形成一个映射关系,查询出的数据的字段映射成实体对象里的字段
       property:表示的是实体对象的字段名字
       column:表示的是查询出的数据的列名 -->
  <result column="表的一个字段(可以为任意表的一个字段)" jdbcType="字段类型" property="映射到pojo对象的一个属性(须为type定义的pojo对象中的一个属性)"/>
  <association property="pojo的一个对象属性" javaType="pojo关联的pojo对象">
    <id column="关联pojo对象对应表的主键字段" jdbcType="字段类型" property="关联pojo对象的主席属性"/>
    <result  column="任意表的字段" jdbcType="字段类型" property="关联pojo对象的属性"/>
  </association>
  <!-- 集合中的property须为oftype定义的pojo对象的属性-->
  <collection property="pojo的集合属性" ofType="集合中的pojo对象">
    <id column="集合中pojo对象对应的表的主键字段" jdbcType="字段类型" property="集合中pojo对象的主键属性" />
    <result column="可以为任意表的字段" jdbcType="字段类型" property="集合中的pojo对象的属性" />  
  </collection>
</resultMap>

If the collection tag uses a nested query, the format is as follows:

 <collection column="传递给嵌套查询语句的字段参数" property="pojo对象中集合属性" 
 ofType="集合属性中的pojo对象" select="嵌套的查询语句" > 
 </collection>

! ! ! The column in the label: the parameter to be passed to the select query statement. If multiple parameters are passed, the format is column= ” {parameter name 1=table field 1, parameter name 2=table field 2}.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325853459&siteId=291194637