我有一个如下的实体:
@Entity
@Table(name = "Category")
public class Category implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@Column(name = "name")
private String name;
@Column(name = "color")
@JsonInclude(Include.NON_NULL)
private String color;
@ManyToOne(cascade = { CascadeType.ALL })
@JsonInclude(Include.NON_NULL)
@JoinColumn(name = "parent_id")
@JsonManagedReference
private Category parent;
@OneToMany(mappedBy = "parent")
@JsonInclude(Include.NON_NULL)
@JsonBackReference
private Set<Category> subcategories = new HashSet<Category>();}
我正在使用findAll()
中的JPA repo
,我到目前为止的是类别列表和父作为子项:
{
"id": 7,
"name": "Home",
"parent": {
"id": 1,
"name": "News",
"color": "#d50000"
}
},
我想要的是相反的,父母和孩子的清单,我需要改变什么?