19、<resultMap>中 <collection>实现多级标签

发布时间 2023-03-31 00:52:53作者: 爱文(Iven)

一、需求:

SQL方式实现多级标签,类似于:

 

二、一级标签实体类声明:

 

三、二级标签实体类声明:

 

四、mybatis标签映射:

<resultMap>中的 <collection>来实现一对多映射关系:

<resultMap id="BaseResultMap" type="com.xxx.model.PageDemo" >
    <id column="uuid" property="uuid" jdbcType="VARCHAR" />
    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="type" property="type" jdbcType="VARCHAR" />
    <result column="status" property="status" jdbcType="VARCHAR" />
    <collection property="otherDemoList" ofType="com.xxx.model.OtherDemo">
      <id column="uuid" jdbcType="VARCHAR" property="uuid" />
      <result column="name" property="name" jdbcType="VARCHAR" />
    </collection>
  </resultMap>

 

mybatis相关参考;