MyObject:
long id;
long parentId;
long index;
List<MyObject> child;
顶级parentId = 0
.....如何根据index排序。。。。
现在好像是 默认的字典排序 蛋疼
Java排序,Java8方法
外层排序直接
list.sort(Comparator.comparing(t -> ((MyObject) t).getIndex()));
外层排序好了过后再循环排序里面的
list.forEach(t->{
((MyObject)t).getChild().sort(Comparator.comparing(MyObject::getIndex));
});
我昨天刚整理了一个,你可以参考一下
https://blog.csdn.net/u010808135/article/details/87709144
private List<TextbookChapterTreeBO> children;
public List<TextbookChapterTreeBO> getChildren() {
children.forEach(t->{
((TextbookChapterTreeBO)t).getChildren().sort(Comparator.comparing(TextbookChapterTreeBO::getIndex));
});
return children;
}
public void setChildren(List<TextbookChapterTreeBO> children) {
this.children = children;
}
把这个排序加到bean里就行了