在今天1024这个程序员节我先定一个题目得一个勋章,一会儿对应标题写一篇,先去恰个饭
来了来了
来说说为什么会出现这个情况,实际问题就是有多个联合表,我们知道mybatis的重点就是返回集的结果映射,那么那么多数据库的字段联合查询应该怎么办呢,所以我就想新建一个类里面封着各个表的实体类

package com.ssm.entity;

import java.util.Date;

public class OrderLand{
 
	private HappyFarmUser happyFarmUser;
	
	private HappyFarmSeller happyFarmSeller;
	
	private OrderforSeller orderforSeller;
	
	private HappyFarmLandinfo happyFarmLandinfo;
	
	private Logistics  logistics;
	
	private Address   address;
	
	private OrderEnd orderend;
	
	private OrderforBuyer orderforBuyer

}

这个就可以把xml的对应的值映射到实体类中了,然后我就查询所有发现只出现第一个
只能映射最后一个对象,我就想想肯定是覆盖了,那么为什么会覆盖呢,让我们来看看修改后不覆盖的

  <resultMap id="BaseResultMap11" type="com.ssm.entity.OrderforBuyer">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="orderId" jdbcType="VARCHAR" property="orderid" />
    <result column="userId" jdbcType="INTEGER" property="userid" />
    <result column="productId" jdbcType="VARCHAR" property="productid" />
    <result column="goodNumber" jdbcType="INTEGER" property="goodnumber" />
    <result column="addressId" jdbcType="INTEGER" property="addressid" />
    <result column="orderStatus" jdbcType="INTEGER" property="orderstatus" />
    <result column="orderTime" jdbcType="TIMESTAMP" property="ordertime" />
    <result column="userphone" jdbcType="VARCHAR" property="userphone" />
		 <association property="orderend" javaType="com.ssm.entity.OrderEnd">
		  	<id column="id" jdbcType="INTEGER" property="id" />
		    <result column="orderId" jdbcType="VARCHAR" property="orderid" />
		    <result column="orderEnd" jdbcType="INTEGER" property="orderend" />
		 </association>
			<association property="happyFarmLandinfo" javaType="com.ssm.entity.HappyFarmLandinfo">
			<id column="landID" jdbcType="INTEGER" property="landid" />
		    <result column="landName" jdbcType="VARCHAR" property="landname" />
		    <result column="landPrice" jdbcType="DOUBLE" property="landprice" />
		    <result column="landImg" jdbcType="VARCHAR" property="landimg" />
		    <result column="landMs" jdbcType="VARCHAR" property="landms" />
		    <result column="landArea" jdbcType="VARCHAR" property="landarea" />
		    <result column="landDate" jdbcType="DATE" property="landdate" />
		    <result column="landSize" jdbcType="VARCHAR" property="landsize" />
		    <result column="status" jdbcType="INTEGER" property="status" />
		</association>
  
		<association property="happyFarmUser" javaType="com.ssm.entity.HappyFarmUser">
			<id column="id" jdbcType="INTEGER" property="id" />
		    <result column="username" jdbcType="VARCHAR" property="username" />
		    <result column="password" jdbcType="VARCHAR" property="password" />
		</association>
		<association property="happyFarmSeller" javaType="com.ssm.entity.HappyFarmSeller">
				    <id column="id" jdbcType="INTEGER" property="id" />
				    <result column="name" jdbcType="VARCHAR" property="name" />
				    <result column="password" jdbcType="VARCHAR" property="password" />
		</association>
	
		<association property="orderforSeller" javaType="com.ssm.entity.OrderforSeller">
		    <id column="id" jdbcType="INTEGER" property="id" />
			<result column="orderId" jdbcType="VARCHAR" property="orderid" />
			<result column="deliveryStatus" jdbcType="INTEGER" property="deliverystatus" />
			<result column="logisticsId" jdbcType="INTEGER" property="logisticsid" />
		</association>

		<association property="logistics" javaType="com.ssm.entity.Logistics">
		    <id column="logisticsId" jdbcType="INTEGER" property="logisticsid" />
		    <result column="logisticsName" jdbcType="VARCHAR" property="logisticsname" />
		</association>
		<association property="address" javaType="com.ssm.entity.Address">
		    	 <id column="addressId" jdbcType="INTEGER" property="addressid" />
    			<result column="addressName" jdbcType="VARCHAR" property="addressname" />
		</association>
  </resultMap>

这个呢是我修改过后的可以查询列表左右的字段,唯一的区别就是有一个id id可以让他们不重复的出现,每一个id对应不一样的字段,所以这样就不会覆盖了。
发现问题的关键在于resultMap中如果不定义类似主键之类的能够区分每一条结果集的字段的话,会引起后面一条数据覆盖前面一条数据的现象