我想在我的jsp上展示这样的东西
CategoryParent1
-次范畴1
-次范畴2
CategoryParent2
-次范畴1
-次范畴2
我能用哪种方式解决它?spring有一些库吗?还是我必须使用一些外部库?
我有一个分类模型
@Entity
public class Category {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String name;
@ManyToOne
private Category parentCategory;
@OneToMany(mappedBy = "parentCategory", cascade = CascadeType.ALL)
private List<Category> childCategories = new ArrayList<>();
public Category() {
}
public Category(String name){
this.name = name;
}
public Category(String name, Category parentCategory) {
this.name = name;
this.parentCategory = parentCategory;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Category getParentCategory() {
return parentCategory;
}
public void setParentCategory(Category parentCategory) {
this.parentCategory = parentCategory;
}
public List<Category> getChildCategories() {
return childCategories;
}
public void setChildCategories(List<Category> childCategories) {
this.childCategories = childCategories;
}
}发布于 2016-07-04 17:42:35
我已经完成了类似的任务,但使用了递归查询。Here is the link 如果您不想使用递归查询。这是你需要做的。
也不要使用List更好地使用Set:
@OneToMany(fetch = FetchType.EAGER, mappedBy="parentCategory", cascade=CascadeType.REMOVE, orphanRemoval=true )
private Set<Categories> childCategories = new HashSet<Categories>();https://stackoverflow.com/questions/38087085
复制相似问题