我正在使用
Hand
类来保存数据。它包括两个相同的内部类Card
,这意味着两个Card
组成一个Hand
。如下:
public class Card {
private Integer id;
private Integer number;
private Integer color;
public Card() {}
public Card(int number, int color) {
this.number = number;
this.color = color;
}
public class Hand {
private Integer id;
private Card card1,card2;
public Hand() {}
public Hand(Card a, Card b) {
card1 = a;
card2 = b;
}
}
然后我像这样制作映射xml:
<resultMap id="handMap" type="com.company.handsmap.Hand">
<id column="id" property="id"/>
<association property="card1" resultMap="cardMap"/>
<association property="card2" resultMap="cardMap"/>
</resultMap>
<resultMap id="cardMap" type="com.company.handsmap.Card">
<id column="id" property="id"/>
<result column="number" property="number"/>
<result column="color" property="color"/>
</resultMap>
<select id="getAllHand" resultMap="handMap">
SELECT
*
FROM Hand H
LEFT JOIN Card c1 ON H.card1_id = c1.id
LEFT JOIN Card c2 ON H.card2_id = c2.id
</select>
因为它表明
Hand
得到了正确的Card
1但是在null
2中得到了
Card
如果我跑
SELECT
*
FROM Hand H
LEFT JOIN Card c1 ON H.card1_id = c1.id
LEFT JOIN Card c2 ON H.card2_id = c2.id
有人能告诉我问题出在哪里,我该如何解决?非常感谢!