java 递归查询树形结构

时间:2021-11-20 11:39:43
  CREATE TABLE "T_MB_PEAK_POWERTYPE"
("TYPEID" NUMBER(4,0) NOT NULL ENABLE,
"TYPENAME" VARCHAR2(100 BYTE) NOT NULL ENABLE,
"UPTYPEID" NUMBER(4,0),
"TYPELEVEL" NUMBER(4,0) NOT NULL ENABLE,
"ORDERNO" NUMBER(4,0),
"DESCRIBE" VARCHAR2(255 BYTE),
"VALID" VARCHAR2(8 BYTE)

   COMMENT ON COLUMN "BSP_HUABEI"."T_MB_PEAK_POWERTYPE"."TYPEID" IS '类别ID';
 
   COMMENT ON COLUMN "BSP_HUABEI"."T_MB_PEAK_POWERTYPE"."TYPENAME" IS '类别名称';
 
   COMMENT ON COLUMN "BSP_HUABEI"."T_MB_PEAK_POWERTYPE"."UPTYPEID" IS '父类别ID';
 
   COMMENT ON COLUMN "BSP_HUABEI"."T_MB_PEAK_POWERTYPE"."TYPELEVEL" IS '类别级别';
 
   COMMENT ON COLUMN "BSP_HUABEI"."T_MB_PEAK_POWERTYPE"."ORDERNO" IS '显示顺序';
 
   COMMENT ON COLUMN "BSP_HUABEI"."T_MB_PEAK_POWERTYPE"."DESCRIBE" IS '注释信息';
 
   COMMENT ON COLUMN "BSP_HUABEI"."T_MB_PEAK_POWERTYPE"."VALID" IS '是否有效(Y有效N表示无效)';


    /**     * 查询树形结构     * @param id : 父id     */    @SuppressWarnings("unchecked")    public void iterative(int id){         String sql = "select typeid , typename , uptypeid , typelevel , orderno  from T_MB_PEAK_POWERTYPE where uptypeid = ? ";       List<HashMap<String , Object>> list = super.getJdbcTemplate().query(sql, new Object[]{id} ,new MyRowMapper()) ;      if(list!=null && list.size() >0){        for(HashMap<String , Object> map : list){          // 主键id          int typeid = TypeUtil.toInt(map.get("typeid"));          String typename = String.valueOf(map.get("typename"));          System.out.println(typename);          iterative(typeid);        }      }     }