mybatis的一對多,select標籤有兩個collection需要注意的一個地方

一、mybatis的xml文件

<resultMap extends="BaseResultMap" id="detailInfoResultMap" type="XXX">
    <id column="student_id" jdbcType="VARCHAR" property="studentId" />

    <collection property="scoreList" column="studentId" javaType="java.util.List" ofType="XXX">
      <id column="score_id" jdbcType="VARCHAR" property="scoreId" />
      <result column="student_id" jdbcType="VARCHAR" property="studentId" />
    </collection>

    <collection property="courseList" column="studentId" javaType="java.util.List" ofType="XXX">
      <id column="course_id" jdbcType="VARCHAR" property="courseId" />
      <result column="student_id" jdbcType="VARCHAR" property="studentId" />
    </collection>
  </resultMap>

二、一般正常集合是一個課程對應一個分數,scoreList有多少條記錄,courseList就有多少條記錄。

如果兩個集合list沒有這樣的對應關係,有可能有對象全部屬性null的數據。如scoreList真實數據10條,courseList真實有5條,courseList還有字段全部爲null的5條數據。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章