Answer the question
In order to leave comments, you need to log in
What is the best way to make a multi-level menu in JPA SpringBoot?
It is necessary to make a multi-level menu, something like this should be the result:
- Menu Item 1
+ Submenu Item 1
+ Submenu Item 2
- Submenu Item 3
+ Sub_Submenu Item 1
+ Sub_Submenu Item 2
- Menu Item 2
+ Submenu Item 1
+ Submenu Item 2
@Entity
@Table(name = "category" )
public class Category {
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
private Integer id;
private String name;
@ManyToOne @JoinColumn(name="parent_id") @JsonIgnore
// @ColumnDefault("0")
private Category parentId;
@OneToMany(mappedBy="parentId")
private List<Category> subCategories=new ArrayList<>();
}
@Entity
@Table(name = "app_category")
public class Category {
@Id
@GeneratedValue
private Long id;
@Column(name = "name", nullable = false)
private String name;
@ManyToOne
@JoinColumn(name = "parentid")
private Category parent;
@OneToMany(mappedBy = "parent")
private Set<Category> childCategories;
// https://github.com/Damiox/ecommerce-rest-spring-jpa
@Entity
@Table(name = "MENU")
public class Menu {
@Id
@Column(name = "ID")
private int id;
@Column(name = "NAME")
private String name;
@OneToMany
@JoinColumn(name = "FATHER", referencedColumnName = "ID")
private List<Menu> childMenu;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question