java Mybatis 递归Ztree树

第一步:通过获取orgID去查询树:

public ResponseData listAllOrgnization(HttpServletRequest request){


    Map map=UserUtil.getUser(request);
    String uid=String.valueOf(map.get("uid"));
    User user = userMapper.getUser(uid);
    String org_id=user.getOrg_id();
    QueryWrapper w_org=new QueryWrapper<>();
    w_org.eq("org_state","2");
    w_org.eq("id",org_id);
    w_org.and(Wrapper -> Wrapper.eq("org_cl_state", "2").or().eq("org_hj_state", "112").or().eq("org_bg_state", "12").or().eq("org_cx_state", "1112"));

  /*  w_org.and(Wrapper -> Wrapper.eq("org_cl_state", "2").or().isNull("org_cl_state"));
    w_org.and(Wrapper -> Wrapper.eq("org_hj_state", "112").or().isNull("org_hj_state"));
    w_org.and(Wrapper -> Wrapper.eq("org_bg_state", "12").or().isNull("org_bg_state"));
    w_org.and(Wrapper -> Wrapper.eq("org_cx_state", "1112").or().isNull("org_cx_state"));*/
    //w_org.and(Wrapper -> Wrapper.eq("org_cl_state", "1").or().eq("org_hj_state", "111").or().eq("org_bg_state", "11").or().eq("org_cx_state", "1111"));
    List w_org_list=baseMapper.selectList(w_org);
    List w_org_list_all=new ArrayList();
    for(M_Organization org:w_org_list){
        w_org_list_all = buildChilTree(org.getId(),w_org_list_all);
        //w_org_list.addAll(w_org_list_all);
    }
    w_org_list.addAll(w_org_list_all);

    return ResponseData.success(ResponseData.DEFAULT_SUCCESS_CODE,ResponseData.DEFAULT_SUCCESS_MESSAGE,w_org_list);
}

 

第一步:递归方法

// 递归获取子节点数据
public List  buildChilTree (String pid,
                                      List w_org_list_all) {
    QueryWrapper w_org=new QueryWrapper<>();
    w_org.eq("pId",pid);
    w_org.eq("org_state","2");
    w_org.and(Wrapper -> Wrapper.eq("org_cl_state", "2").or().eq("org_hj_state", "112").or().eq("org_bg_state", "12").or().eq("org_cx_state", "1112"));
    List org_child_list = baseMapper.selectList(w_org);
    w_org_list_all.addAll(org_child_list);
    for(M_Organization org :org_child_list){
        buildChilTree(org.getId(),w_org_list_all);
    }
  return w_org_list_all;
}

你可能感兴趣的:(mybatis_plus笔记)