首页 > 代码库 > mybatis一对多

mybatis一对多

 <resultMap type="entity.Grade" id="GradeResult">
    <id column="gid" jdbcType="INTEGER" property="gid"/>
    <result column="gname" jdbcType="VARCHAR" property="gname"/>
    <result column="gdesc" jdbcType="VARCHAR" property="gdesc"/>
    <!-- 一对多关系 -->
    <!-- <collection property="stus" resultMap="Student.StudentResult"></collection>  -->
    <collection property="stus" javaType="entity.Student">
        <id property="sid" column="sid"/>
        <result property="sname" column="sname"/>
        <result property="sex" column="sex"/>
    </collection>
  </resultMap>


<resultMap type="entity.Student" id="StudentResult">
    <id column="sid" jdbcType="INTEGER" property="sid"/>
    <result column="sname" jdbcType="VARCHAR" property="sname"/>
    <result column="sex" jdbcType="VARCHAR" property="sex"/>
    <!-- 多对一 -->
   <!--  <association property="grade" resultMap="Grade.GradeResult"></association> -->
    <association property="grade" javaType="entity.Grade">
        <id property="gid" column="gid"/>
        <result property="gname" column="gname"/>
        <result property="gdesc" column="gdesc"/>
    </association>
  </resultMap>

mybatis一对多