zoukankan      html  css  js  c++  java
  • mysql 实现 start with

    自己写service----> 传入map(idsql,rssql,prior)   idsql 查询id   rssql 查询结果集    调用 以下方法

    @param ids 要查询的起始 start with
    * @param allres 包含要递归数据的结果集 ( 查询时别名ID PID )
    * @param pos prior---> UP or DOWN
    * @return
    */
    public static List<Map<String, Object>> getTree(ArrayList<String> ids,
    List<Map<String, Object>> allres,String pos) {
    List<Map<String, Object>> res=new ArrayList<Map<String,Object>>();

    if("up".equals(pos)){
    res=toCreatTreeUp(ids,allres,res);
    }
    if("down".equals(pos)){
    res=toCreatTreeDown(ids,allres,res);
    }
    return res;
    }
    private static List<Map<String, Object>> toCreatTreeUp(ArrayList<String> ids,
    List<Map<String, Object>> allres,List<Map<String, Object>> res) {
    ArrayList<String> idss = new ArrayList<String>();
    for(String id :ids){
    for (Map<String, Object> map : allres) {
    if(id.equals(map.get("ID").toString())){
    idss.add(map.get("PID").toString());
    res.add(map);
    }
    }
    }
    if (idss.size()!=0) {
    ids = idss;
    res = toCreatTreeUp(ids,allres,res);
    }
    return res ;
    }
    private static List<Map<String, Object>> toCreatTreeDown(ArrayList<String> ids,
    List<Map<String, Object>> allres,List<Map<String, Object>> res) {
    ArrayList<String> idss = new ArrayList<String>();
    for(String id :ids){
    for (Map<String, Object> map : allres) {
    if(id.equals(map.get("ID").toString())){
    res.add(map);
    }
    if(id.equals(map.get("PID").toString())){
    idss.add(map.get("ID").toString());
    }
    }
    }
    if (idss.size()!=0) {
    ids = idss;
    res = toCreatTreeDown(ids,allres,res);
    }
    return res ;
    }

  • 相关阅读:
    springboot属性类自动加载配置文件中的值
    mysql修改root密码
    idea各种图标说明
    nginx安装配置
    notepad++下载32位,安装插件管理
    crontab 定时执行脚本出错,但手动执行脚本正常
    jenkins安装配置
    VirtualBox从USB设备(PE)启动图文教程
    如何卸载windows的服务?卸载服务?
    在Windows的CMD中如何设置支持UTF8编码?
  • 原文地址:https://www.cnblogs.com/sx2zx/p/6229260.html
Copyright © 2011-2022 走看看