哦,如果categorys和本身也有对应关系的话,那就好说了啊,可以试着这么写:
............
select b from Books b,Categorys c1,Categorys c2 where b.categorys_id = b.id and b.parent_id = c.id
...........
当然,里面还应该加其他的一些判断条件,判断Categorys是第一层的还是第二层的
............
select b from Books b,Categorys c1,Categorys c2 where b.categorys_id = b.id and b.parent_id = c.id
...........
当然,里面还应该加其他的一些判断条件,判断Categorys是第一层的还是第二层的
是categorys 和本身有一个关系.
public List buildCategoryTree(rootid){
List result = new ArrayList();//存放最终结果
//根据rootid查找其子节点
List subCategory = findByParentId(rootid);
//循环子节点信息
if(subCategory.size() == 0) result.add(rootid);//如果没有子节点,把自己加入
else{
for(Iterator subItr = subCategory.iterator(); subItr.hasNext();){
Category cg = (Category)subCategory.next();
result.addAll(buildCategoryTree(cb.getId());
}
}
return result;
}
这里只是单纯的建Category树的方法,如果还要加入Book的话要麻烦一些,自己按照这个思路写