Class A {
public int ID;
public int Rating1;
public int Rating2;
public int Rating3;
public B mRating1;
public B mRating2;
public B mRating3;
}
Class B {
public int ID;
public String Code;
public String NameEn;
public String NameCn;
public int IsActive;
}
<resultMap id="BaseResultMap" type="com.example.demo1.demo.system.dao.entities.dbo.tbA">
<id column="ID" jdbcType="INT" property="Id" />
<result column="Rating1" jdbcType="INT" property="Rating1" />
<result column="Rating2" jdbcType="INT" property="Rating2" />
<result column="Rating3" jdbcType="INT" property="Rating3" />
<association property="mRating1" resultMap="com.example.demo1.demo.system.dao.mapper.tbBMapper.BaseResultMap"></association>
<association property="mRating2" resultMap="com.example.demo1.demo.system.dao.mapper.tbBMapper.BaseResultMap"></association>
<association property="mRating3" resultMap="com.example.demo1.demo.system.dao.mapper.tbBMapper.BaseResultMap"></association>
</resultMap>
SELECT A.*,B.*,C.*,D.*
FORM tb_A A
LEFT JOIN tb_B B ON A.Rating1=B.ID
LEFT JOIN tb_B C ON A.Rating1=C.ID
LEFT JOIN tb_B D ON A.Rating1=D.ID
如上所述,A的对象中3个Rating字段关联B对象的ID,分另可以取到每一个分值的 Code, 英文名,中文名,是否有效等。我在定义ResultMap时,将B对象相应的Map包含在A的ResultMap中了。使用上面的SQL语句查询,但查询出来,只有mRating1这个对象有值,另外两个分值对象为空,Mybatis是如何关联这个查询结果集的。是需要在 association 设置对应的关联参数吗?