Mybatis中实现递归查询

在Mybatis中实现递归查询,父类嵌套子类

xml:

这里注意

<collection column="{id=id,robotIp=robot_ip}" property="children" ofType="com.yuneasy.robort.vo.showEntity.StringTree" select="selectByAreaPidTwo2">

    </collection>

column=“{prop1=col1,prop2=col2}”,这个是条件,会在selectByAreaPidTwo2方法中用到。

 <resultMap id="areaListResult" type="com.yuneasy.robort.vo.showEntity.StringTree" >
	<id column="key_id" property="keyId"></id>
    <result column="id" property="id" jdbcType="VARCHAR" />
    <result column="pid" property="pid" jdbcType="VARCHAR" />
    <result column="robot_ip" property="robotIp" jdbcType="VARCHAR" />
    <result column="name" property="name" jdbcType="VARCHAR" />
    
	<collection column="{id=id,robotIp=robot_ip}" property="children" ofType="com.yuneasy.robort.vo.showEntity.StringTree" select="selectByAreaPidTwo2">

	</collection>
</resultMap>
  
   <select id="selectByAreaPidTwo2"  resultMap="areaListResult" parameterType="java.util.Map">
  	SELECT a.id as key_id,  a.area_id as id, a.area_pid as pid, a.robot_ip, b.name 
  	from device_config a
  	LEFT JOIN device_config_base b on a.base_id=b.id
  	<where>
  		<if test="id != null">
  			 a.area_pid = #{id}
  		</if>
  		<if test="robotIp != null">
  			and a.robot_ip = #{robotIp}
  		</if>
  	</where>
  </select>

 

vo:

@Getter
@Setter
public class StringTree implements Serializable {

	private static final long serialVersionUID = 1L;

	private String keyId;

	private String id;

	private String pid;

	private String name;

	private String pointId;

	private List<StringTree> children;

//	private String type;

	private String robotIp;

	

}

 

dao:

List<StringTree> selectByAreaPidTwo2(Map<String, String> map);

swagger测试结果类似下面这个:

{

  "data": {
    "list": [
      {
        "goodscateid": 1,
        "name": "食品类",
        "parentid": 0,
        "description": "11111111111111111",
        "displayorder": 1,
        "commissionrate": null,
        "enabled": 1,
        "catelist": [
          {
            "goodscateid": 2,
            "name": "生鲜类",
            "parentid": 1,
            "description": "222222222222222",
            "displayorder": 2,
            "commissionrate": null,
            "enabled": 1,
            "catelist": [
              {
                "goodscateid": 3,
                "name": "海鲜类",
                "parentid": 2,
                "description": "3333333",
                "displayorder": 3,
                "commissionrate": null,
                "enabled": 1,
                "catelist": []
              }
            ]
          }
        ]
      },
      {
        "goodscateid": 4,
        "name": "服装类",
        "parentid": 0,
        "description": "服装生成商",
        "displayorder": 2,
        "commissionrate": null,
        "enabled": 1,
        "catelist": []
      }
    ],
    "prePage": 0,
    "nextPage": 0,
    "isFirstPage": true,
    "isLastPage": true,
    "hasPreviousPage": false,
    "hasNextPage": false,
    "navigatePages": 8,
    "navigatepageNums": [
      1
    ],
    "navigateFirstPage": 1,
    "navigateLastPage": 1,
    "firstPage": 1,
    "lastPage": 1
  }
}

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值