mybatis多表操作:
一对一:association
(1)不推荐
<resultMap type="Student" id="studentResultMap2">
property属性指的是java实体类的属性名,column指的是数据库的字段名,id标签指的数据主键字段
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="age" column="age"/>
通过对象属性进行关联
<result property="sgroup.gid" column="gid"/>
<result property="sgroup.gname" column="gname"/>
</resultMap>
(2):association 不推荐
<resultMap type="Student" id="studentResultMap2">
<!-- property属性指的是java实体类的属性名,column指的是数据库的字段名,id标签指的数据主键字段 -->
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="age" column="age"/>
<association property="sgroup" javaType="Sgroup">
<id property="gid" column="gid"/>
<result property="gname" column="gname"/>
</association>
</resultMap>
(3)<resultMap type="Student" id="studentResultMap2">
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="age" column="age"/>
<association property="sgroup" resultMap="sgroupResultMap"/>
</resultMap>
<resultMap type="Sgroup" id="sgroupResultMap">
<id property="gid" column="gid"/>
<result property="gname" column="gname"/>
</resultMap>
(4)与前边的3种思想不一样
<resultMap type="Student" id="studentResultMap">
<id property="id" column="id"/>
<result property="name" column="name"/>
<result property="age" column="age"/>
<association property="sgroup" column="gid" select="org.lanqiao.dao.SgroupDao.selectSgroupByGid"/>
</resultMap>