建表開始
一對一
1---外鍵在附屬表 ,建實體類 實體類不要有那個外鍵 ,具體關聯查找的bean屬性在附屬實體類里建,即外鍵在哪個實體類屬性就在哪建!
2---兩個bean建好,mapper接口 mapper.xml配置rsultmap
<resultmap type="附屬表bean的具體類路徑 id=“xxx”">
<result column="表的字段" property="實體類字段"/>
。。。。
<association property="附屬表的實體bean屬性名稱" javaType="附屬表的實體bean的類路徑">
<id property="關聯查找的bean的主鍵字段表示" column="對應的表主鍵"/>
<result column="表的字段" property="實體類字段"/>
。。。。
</association >
</resultmap>
一對多
1--表建好 外鍵在多的一方 實體類建好 關聯查找的list集合在一的一方 與上面相反
2--mapper接口mapper.xml
<resultmap type="一的一方類路徑“ id=“xxx”">
<result column="表的字段" property="實體類字段"/>
。。。。
<collection property="list屬性名稱" javaType="list里面單個泛型的類路徑">
<id property="list里面單個泛型的實體類的id表示字段" column="對應的表主鍵"/>
<result column="表的字段" property="實體類字段"/>
。。。。
</association >
</resultmap>
