MyBatis返回树形结构数据

<!--父方法返结果集-->  
<resultMap id="ServiceMachineResultMap" type="com.zhishoubao.rms.pojo.vo.ServiceMachineLaneInfoVo">
    <result column="lane_id" property="laneId" jdbcType="INTEGER" />
    <result column="service_machine_id" property="serviceMachineId" jdbcType="VARCHAR" />
    <result column="searchName" property= "searchName" jdbcType="VARCHAR" />
    <result column="bannerSuffix" property="bannerSuffix" jdbcType="VARCHAR" />
    <result column="picUrlPrefix" property="picUrlPrefix" jdbcType="VARCHAR" />
   <!--传递给子SQL的参数,以及子SQL名称-->    
   <collection column="{serviceMachineId=service_machine_id,laneId=lane_id,picUrlPrefix=picUrlPrefix,bannerSuffix=bannerSuffix,searchName=searchName}" property="serviceMachineLaneInfo" javaType="ArrayList"
                ofType="com.zhishoubao.rms.pojo.vo.ServiceCargoRoadInfoVo" select="queryGoodsStockInfo"/>
  </resultMap>
<!--父方法,查询设备货道列表 --> 
<select id="queryServiceMachineLaneInfo" resultMap="ServiceMachineResultMap"
          parameterType="com.zhishoubao.rms.pojo.command.QueryServiceMachineGoodStockCommand">
    SELECT
        lane_id,
        service_machine_id,
        #{searchName} AS searchName,
        #{bannerSuffix} AS bannerSuffix,
        #{picUrlPrefix} AS picUrlPrefix
    FROM
        service_machine_goods_stock_test
    WHERE
        service_machine_id = #{serviceMachineId}
    GROUP BY lane_id
  </select>
 <!--子方法返结果集-->
  <resultMap id="ServiceMachineLaneResultMap" type="com.zhishoubao.rms.pojo.vo.ServiceCargoRoadInfoVo">
    <result column="goods_name" property="goodsName" jdbcType="VARCHAR" />
    <result column="goods_banner_url" property="goodsBannerUrl" jdbcType="VARCHAR" />
    <result column="goods_id" property="goodsId" jdbcType="VARCHAR" />
    <result column="renting_count" property="rentingCount" jdbcType="INTEGER" />
    <result column="lost_count" property="lostCount" jdbcType="INTEGER" />
    <result column="rent_count" property="rentCount" jdbcType="INTEGER" />
  </resultMap>
<!--子方法,查询设备货道列表中的商品信息--> 
<select id="queryGoodsStockInfo" resultMap="ServiceMachineLaneResultMap"
          parameterType="com.zhishoubao.rms.pojo.command.QueryServiceMachineGoodStockCommand">
    SELECT
      A.goods_id,
      A.goods_name,
      CONCAT(#{picUrlPrefix}, /, A.goods_banner_url, #{bannerSuffix}) goods_banner_url,
      B.lost_count,
      B.renting_count,
      B.rent_count
    FROM A
    LEFT JOIN B ON A.goods_id = B.goods_id
    GROUP BY A.goods_id
  </select>
经验分享 程序员 微信小程序 职场和发展