mybatis 递归

<!-- 递归查询 map -->
<resultMap id="RecursionMap" type="com.ws.project.transfer.project.xin.wbs.entity.CodeTree">
  <id column="ID" jdbcType="VARCHAR" property="id" />
  <result column="PID" jdbcType="VARCHAR" property="pid" />
  <result column="CODE" jdbcType="VARCHAR" property="code" />
  <result column="NAME" jdbcType="VARCHAR" property="name" />
  <result column="LEVELON" jdbcType="DECIMAL" property="levelon" />
  <result column="ORDERBY" jdbcType="DECIMAL" property="orderby" />
  <result column="DEMO" jdbcType="VARCHAR" property="demo" />
  <result column="EXTFIELD" jdbcType="VARCHAR" property="extfield" />
  <result column="OPERUSER" jdbcType="VARCHAR" property="operuser" />
  <result column="OPERTIME" jdbcType="TIMESTAMP" property="opertime" />
  <collection property="codeTrees" ofType="com.ws.project.transfer.project.xin.wbs.entity.CodeTree" column="id" select="findChild" />
</resultMap>
<!-- 递归查询 sep1: 根 -->
<select id="recursion" resultMap="RecursionMap">
  <!-- 不要当前节点,所以是 PID = #{id} -->
  SELECT <include refid="Base_Column_List" /> FROM T_CODE_TREE WHERE PID = #{id}
</select>
<!-- 递归查询 sep2:子节点 -->
<select id="findChild" resultMap="RecursionMap">
  SELECT <include refid="Base_Column_List" /> FROM T_CODE_TREE WHERE PID = #{id}
</select>
posted @ 2021-08-17 10:20  huanggy  阅读(259)  评论(0编辑  收藏  举报