Mapper.xml

发布时间 2023-12-15 15:41:12作者: 应景的BGM

<resultMap id="resuleMap" type="com.com.entity.xxx">

  <id property="id" column="id"></id>

  <result property="xxx" column="xxx"></result >

  <result property="xxx" column="xxx"></result >

  <association property="entity" column="entity_id" select="selectentityById"> </association > //@TableField(exist = false) 

  <collection property="entityList" column="id" javaType="ArrayList" select="selectentityById"> </collection>

</resultMap>

<select id="selectentityById" parameterType="String" resultType="com.com.entity.xxx" >

  select * from xxx where xxx_id = #{xxxid}

</select>

<select id="selectentityById" parameterType="String" resultType="com.com.entity.xxx" >

  select * from xxx where id = #{id}

</select>

——————————————————————————————————————————————————————

<resultMap id="resuleMap" type="com.com.entity.xxx">

  <id property="id" column="id"></id>

  <result property="xxx" column="xxx"></result >

  <result property="xxx" column="xxx"></result >

  <collection property="entityList" ofType="com.com.entity.xxx" > //@TableField(exist = false)

    <id property="xxx_id" column="xxx_id"></id>

    <result property="xxx" column="xxx"></result >

    <result property="xxx" column="xxx"></result >

 

  </collection>

</resultMap>

 

<select id="selectentityById" parameterType="String" resultType="resuleMap" >

  select 

    ca.*,

    ct.*,

    ct.id as xxx_id

  from

    xxx ca

    left join xxx ct on ca.id = ct.xxxid

  where

    id = #{id}

</select>