HashMap> results = new HashMap>();
//输入的ID
int ID=Integer.parseInt(Catid);
//表中所有的数据
aas=cloudnewscategory.selectAllGory();
System.out.println("所有记录="+aas);
for (CloudNewsCategory gory : aas) {
System.out.println("536456747="+results.get(gory.getPARENTID()));
List<CloudNewsCategory> beans = results.get(gory.getPARENTID());
if (beans == null) {
beans = new ArrayList<CloudNewsCategory>();
results.put(gory.getPARENTID(), beans);
}
beans.add(gory);
}
displayMap(results,ID,"");
public static void displayMap(HashMap<Integer, List<CloudNewsCategory>> results,
int startKey, String str) {
List<CloudNewsCategory> list = results.get(startKey);
// System.out.println("shuji="+results.get(startKey));
for (CloudNewsCategory gory : list) {
vv.add(gory.getID());
System.out.println(str + gory.getID() + "|"+gory.getCATEGORY());
if (results.containsKey(gory.getID())) {
displayMap(results, gory.getID(), str + " ");
}
}
}
控制台打印如下:![图片说明](https://img-ask.csdn.net/upload/201508/20/1440034025_984725.png)
怎么得到一个list 里面是所有的子ID阿 急求~~~~~