<result property="实体类属性" column="数据库表列名"/>
<result property="实体类属性" column="数据库表列名"/>
<result property="实体类属性" column="数据库表列名"/>
<result property="实体类属性" column="数据库表列名"/>
<result property="实体类属性" column="数据库表列名"/>
<result property="实体类属性" column="数据库表列名"/>
</association>
</resultMap>
<association>元素有两种配置方式:嵌套查询和嵌套结果。
Mybatis 在映射文件中加载关联关系对象主要通过两种方式:嵌套查询和嵌
套结果。嵌套查询时指通过执行另一条 SQL 映射语句来返回预期的复杂类型;
嵌套结果是使用嵌套结果映射来处理重复的联合结果的子集。
<!—嵌套查询-->
<!-- 一对一,association 使用 select 属性引入另一条 SQL 语句 -->
<association property="score" column="studentId"
javaType="Score"
select ="com.ghl.mapper.ScoreMapper.findScoreByStudentId"/>
</resultMap>
<!—嵌套结果-->
<association property=”card” javaType=”com.ssm.pojo.StudentIdCard”>
<id property=”id” column=”card_id”/>
<result property=”code” column=”code”/>
</association>
使用 Mybatis 的 association 标签的注意事项:
association 标签是放在 resultMap 标签体内部的,在 select 标签的 resultMap
属性中配置 resultMap 标签的 id 名 mybatis 方可识别。(注意 resultMap 标签和
resultMap 属性是不同的,resultMap 标签是一个标签体可以配置 id 属性和 type
属性,而 resultMap 属性是放在标签体内部的,需要配置 resultMap 标签的 id 属
评论0
最新资源