溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

在MyBatis中如何將Mapper文件引用到resultMap中

發(fā)布時間:2020-11-27 16:21:29 來源:億速云 閱讀:578 作者:Leah 欄目:編程語言

今天就跟大家聊聊有關在MyBatis中如何將Mapper文件引用到resultMap中,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據(jù)這篇文章可以有所收獲。

ClassesMapper.xml:

<resultMap type="Classes" id="classesMap">
    <id property="id" column="c_id" javaType="int"/>
    <result property="name" column="c_name" javaType="String"/>
<!--  <association property="teacher" javaType="Teacher" >
      <id property="id" column="t_id" javaType="int"/>
      <result property="name" column="t_name" javaType="String"/>
      <result property="age" column="t_age" javaType="int"/>
    </association> -->
    <association property="teacher" javaType="Teacher" resultMap="com.lsj.test.mybatis.mapper.TeacherMapper.teacherMap" ></association>
    <collection property="studentList" ofType="Student" resultMap="com.lsj.test.mybatis.mapper.StudentMapper.studentMap" ></collection>   
  </resultMap>
  <sql id="selectAllClassesSql">
    SELECT 
        c.id as c_id,c.name as c_name,teacher_id,
        t.id as t_id,t.name as t_name,t.age as t_age,
        s.id as stu_id,s.name as stu_name,s.classes_id 
    from classes c,teacher t,student s
  </sql>

TeacherMapper.xml的resultMap:

 <resultMap type="Teacher" id="teacherMap">
    <id property="id" column="t_id" javaType="int"/>
    <result property="name" column="t_name" javaType="String"/>
    <result property="age" column="t_age" javaType="int"/> 
  </resultMap>

利用命名空間+resultMapID就可以直接引用其他Mapper文件的resultMap,其中resultMap的column在本文件中也有用,也可以對應sql語句中的column別名。

看完上述內容,你們對在MyBatis中如何將Mapper文件引用到resultMap中有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業(yè)資訊頻道,感謝大家的支持。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI