mybatis 使用(2)一对一关联映射

IdcardMapper.xml

<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mybatis.mapper.IdcardMapper">
	<!-- 根据id查询身份证信息 -->
	<select id="findIdcardById" parameterType="int" resultType="Idcard">
		select * from idcard where id=#{id}
	</select>
</mapper>

PersonMapper.xml

<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mybatis.mapper.PersonMapper">
	<!-- 根据id查询 个人信息,返回resultMap -->
	<select id="findPersonById" parameterType="int" resultMap="personMap">
		select
		* from person where id = #{id}
	</select>
	<!-- 查询语句查询结果映射 -->
	<resultMap type="Person" id="personMap">
		<id property="id" column="id" />
		<result property="name" column="name" />
		<result property="age" column="age" />
		<result property="sex" column="sex" />
		<!-- 一对一关联映射 -->
		<association property="idcard" column="cid"
			select="com.mybatis.mapper.IdcardMapper.findIdcardById" javaType="Idcard" />
	</resultMap>
</mapper>
发布了245 篇原创文章 · 获赞 1 · 访问量 9558

猜你喜欢

转载自blog.csdn.net/qq_37769323/article/details/104318466