MyBatis一对一关联

<!-- 一对一 -->
	<select id="findOrdersUser" resultType="com.leech.mybatis.first.pojo.OrdersCustom">
		select orders.*,
			   user.username,user.sex,user.address
 		from orders,user
        where orders.user_id=user.id
	</select>
	
	<resultMap type="com.leech.mybatis.first.pojo.Orders" id="OrdersUserResultMap">
		<id property="id" column="id"/>
		<result property="userId" column="user_id"/>
		<result property="number" column="number"/>
		<result property="createtime" column="createtime"/>
		<result property="note" column="note"/>
		
		<!-- 关联信息 -->
		<association property="user" javaType="com.leech.mybatis.first.pojo.User">
			<id column="user_id" property="id"/>
			<result property="username" column="username"/>
			<result property="sex" column="sex"/>
			<result property="address" column="address"/>
		</association>
		
	</resultMap>
	<!-- 一对一 -->
	<select id="findOrdersUserResultMap" resultMap="OrdersUserResultMap">
		select orders.*,
			   user.username,user.sex,user.address
 		from orders,user
        where orders.user_id=user.id
	</select>


你可能感兴趣的:(MyBatis一对一关联)