//查询一级分类,来源分类表Appcategory,根据id查询一级查询 List oneList = appCategoryService.getOneList(1); System.out.println(oneList + "one"); //查询二级分类 List twoList = new ArrayList(); //查询三级分类 List threeList = new ArrayList(); for (AppCategory app : oneList) { //根据一级查二级,根据查询2 List one = appCategoryService.getOneList(app.getId()); //根据二级检查三级 for (AppCategory two : one) { ///遍历添加二级分类 twoList.add(two); //查询三级分类 List three = appCategoryService.getOneList(two.getId()); for (AppCategory four : three) { ///遍历添加三级分类 threeList.add(four); } } }
原理是根据parentid进行一级分类,他的id为2,所以要根据一级分类的id查询parentid为2的值,查询三级分类等等。(只为自己总结,不要喷)