下面是一个树形结构表自连接 联合查询 Demo
<resultMap id="BaseResultMap" type="com.maidan.daas.entity.AccoSysmanResource" >
<id column="pid" property="pid" jdbcType="INTEGER" />
<result column="createTime" property="createtime" jdbcType="TIMESTAMP" />
<result column="delete_flag" property="deleteFlag" jdbcType="INTEGER" />
<result column="description" property="description" jdbcType="VARCHAR" />
<result column="href" property="href" jdbcType="VARCHAR" />
<result column="name" property="name" jdbcType="VARCHAR" />
<result column="level" property="level" jdbcType="INTEGER" />
<result column="resourceType" property="resourceType" jdbcType="INTEGER" />
<result column="p_menu_id" property="pMenuId" jdbcType="INTEGER" />
<result column="icon" property="icon" jdbcType="VARCHAR" />
</resultMap>
<!--extends="BaseResultMap" resultMap 相同列继承继承 -->
<resultMap type="com.maidan.daas.entity.AccoSysmanResource" id="ShopAccoSysmanResourceTree" extends="BaseResultMap">
<collection property="subResource" javaType="ArrayList"
column="pid" ofType="com.maidan.daas.entity.AccoSysmanResource">
<id column="child_pid" property="pid" jdbcType="INTEGER" />
<result column="child_createTime" property="createtime" jdbcType="TIMESTAMP" />
<result column="child_delete_flag" property="deleteFlag" jdbcType="INTEGER" />
<result column="child_description" property="description" jdbcType="VARCHAR" />
<result column="child_href" property="href" jdbcType="VARCHAR" />
<result column="child_name" property="name" jdbcType="VARCHAR" />
<result column="child_level" property="level" jdbcType="INTEGER" />
<result column="child_resourceType" property="resourceType" jdbcType="INTEGER" />
<result column="child_p_menu_id" property="pMenuId" jdbcType="INTEGER" />
<result column="child_icon" property="icon" jdbcType="VARCHAR" />
<!-- 延迟加载 传递两个参数
{pMenuId=child_pid,userId=userId}
传递查询参数名称=字段名称
-->
<collection property="subResource" javaType="ArrayList" select="getShopChildAccoSysmanResource"
column="{pMenuId=child_pid,userId=userId}" ofType="com.maidan.daas.entity.AccoSysmanResource" >
</collection>
</collection>
</resultMap>
<select id="getShopChildAccoSysmanResource" parameterType="java.util.Map" resultMap="BaseResultMap">
select
*
from acco_sysman_resource where delete_flag = 0
AND p_menu_id=#{pMenuId,jdbcType=INTEGER}
ANDuser_id = #{userId,jdbcType=INTEGER}
</select>