Mybatis标签使用 -association 绑定对象,collection 绑定集合

发布于:2025-05-10 ⋅ 阅读:(21) ⋅ 点赞:(0)

注意
association标签中的 select , column 属性使用
collection 标签中的 ofType 属性使用

@Data
public class Tours implements Serializable {
    private static final long serialVersionUID = 1L;
    
    private Integer touId;
    
    private String tourName;

    private Integer guideId;
    
    private Guides guides;

    private List<Visitors> visitorsList;
}
<resultMap id="BaseResultMap" type="com.rag.bi_2.chaotama.domain.Tours">
    <id column="tou_id" jdbcType="INTEGER" property="touId" />
    <result column="tour_name" jdbcType="VARCHAR" property="tourName" />
    <result column="guide_id" jdbcType="INTEGER" property="guideId" />

    <association property="guides" javaType="com.rag.bi_2.chaotama.domain.Guides" select="com.rag.bi_2.chaotama.mapper.GuidesMapper.selectByPrimaryKey" column="guide_id" >
      <id column="id" jdbcType="INTEGER" property="id" />
      <result column="name" jdbcType="VARCHAR" property="name" />
      <result column="phone" jdbcType="VARCHAR" property="phone" />
    </association>

    <collection property="visitorsList" ofType="com.rag.bi_2.chaotama.domain.Visitors">
      <id column="visitor_id" jdbcType="INTEGER" property="id" />
      <result column="visitor_name" jdbcType="VARCHAR" property="name" />
      <result column="visitor_age" jdbcType="INTEGER" property="age" />
    </collection>
  </resultMap>


网站公告

今日签到

点亮在社区的每一天
去签到