我有一个名为Activite的实体引用自己,(一个Activite可以有很多活动),我试图通过休息服务获得所有活动。 这是实体:
@Entity
public class Activite implements Serializable{
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private long id_act;
private String designation_fr;
private String designation_ar;
private String libelle;
@ManyToOne
private Activite parent;
@OneToMany(mappedBy="parent")
private Collection<Activite> children;
public Collection<Activite> getChildren() {
return children;
}
public void setChildren(Collection<Activite> children) {
this.children = children;
}
@JsonIgnore
public Activite getParent() {
return parent;
}
public void setParent(Activite parent) {
this.parent = parent;
}
这是我得到的Json格式:
[{
"id_act": 1,
"designation_fr": "fr",
"designation_ar": "cfd",
"libelle": "Activite 1",
"children": [
{
"id_act": 11,
"designation_fr": "bhjf",
"designation_ar": "dhbf",
"libelle": "Activite 1.1",
"children": [],
"id_prj": 1
},
{
"id_act": 12,
"designation_fr": "njkj",
"designation_ar": "ffrgrn",
"libelle": "Activite 1.2",
"children": [],
"id_prj": 1
},
{
"id_act": 13,
"designation_fr": "njkdj",
"designation_ar": "frjn",
"libelle": "Activite 1.3",
"children": [
{
"id_act": 131,
"designation_fr": "hcchchc",
"designation_ar": "GFVVHG",
"libelle": "Activite 1.3.1",
"children": [],
"id_prj": 1
}
],
"id_prj": 1
}
],
"id_prj": 1
},
{
"id_act": 11,
"designation_fr": "bhjf",
"designation_ar": "dhbf",
"libelle": "Activite 1.1",
"children": [],
"id_prj": 1
},
{
"id_act": 12,
"designation_fr": "njkj",
"designation_ar": "ffrgrn",
"libelle": "Activite 1.2",
"children": [],
"id_prj": 1
},
{
"id_act": 13,
"designation_fr": "njkdj",
"designation_ar": "frjn",
"libelle": "Activite 1.3",
"children": [
{
"id_act": 131,
"designation_fr": "hcchchc",
"designation_ar": "GFVVHG",
"libelle": "Activite 1.3.1",
"children": [],
"id_prj": 1
}
],
"id_prj": 1
},
{
"id_act": 131,
"designation_fr": "hcchchc",
"designation_ar": "GFVVHG",
"libelle": "Activite 1.3.1",
"children": [],
"id_prj": 1
}
]
这就是我想要的:
[
{
"id_act": 1,
"designation_fr": "fr",
"designation_ar": "cfd",
"libelle": "Activite 1",
"children": [
{
"id_act": 11,
"designation_fr": "bhjf",
"designation_ar": "dhbf",
"libelle": "Activite 1.1",
"children": [],
"id_prj": 1
},
{
"id_act": 12,
"designation_fr": "njkj",
"designation_ar": "ffrgrn",
"libelle": "Activite 1.2",
"children": [],
"id_prj": 1
},
{
"id_act": 13,
"designation_fr": "njkdj",
"designation_ar": "frjn",
"libelle": "Activite 1.3",
"children": [{
"id_act": 131,
"designation_fr": "njkdj",
"designation_ar": "frjn",
"libelle": "Activite 1.3.1",
"children": [],
"id_prj": 1
}],
"id_prj": 1
}
],
"id_prj": 1
}]
如你所见,Activite的id为11 12 13和131是重复的,我希望它们只在children数组中 我实际上是在angularjs中调用其余服务,所以是否可以更改我在angularjs中获得的json格式,或者我应该在后端更改查询
答案 0 :(得分:1)
我希望您已粘贴上面的响应json 。最好更改后端代码以获得所需的正确json,这样您就可以使用json进行进一步处理。