Mybatis 一对一查询
需求:实体是blog 和author 关系是一对一,查询 blog 以及 blog 的作者信息
- 嵌套查询
<select id="selectBlogAuthor" resultMap="blogResultMap" parameterType="int">
select * from blog where bid = #{id, jdbcType=INTEGER}
</select>
<resultMap id="blogResultMap" type="com.chuang.resultmap.BlogResultMap">
<id column="bid" jdbcType="INTEGER" property="bid" />
<result column="name" jdbcType="STRING" property="name" />
<association property="author" colmn="author_id"
select="com.chuang.dao.AuthorMapper.selectByPrimaryKey"/>
<resultMap>