Spring 存储库投影获取一个对象的子项
Spring Repository Projection Get Child of One Object
我经常使用 Spring 存储库接口。一个对我来说工作得很好,但后来我意识到我需要从中得到更多。我想再上一级 get()
我在内部网上工作,因此无法复制和粘贴,但希望以下内容能提供足够的信息使其易于理解...
@Entity
@Table(name="person")
class Person {
...
}
@Entity
@Table(name="requisite")
class Requisite {
...
@OneToOne
@JoinColumn
private Document document;
}
@Entity
@Table(name="person_requisite")
class PersonRequisite {
...
@ManyToOne
@JoinColumn(name="person_id")
private Person person;
...
@ManyToOne
@JoinColumn(name="requisite_id")
private Requisite requisite;
...
}
@Projection(name="personRequisiteProjection", types={PersonRequisite.class})
public interface PersonRequisiteProjection {
...
Person getPerson();
Requisite getRequisite();
...
}
这是我现在得到的结果的表示...
"personRequisites" : [ {
...
"requisite" : {
id : 1,
...
no document object or document id from the requisite
},
"person" : {
id : 33,
...
},
...
]
...
这是我想要的表示...
"personRequisites" : [ {
...
"requisite" : {
id : 1,
...
"document" : {
"id" : 55,
"name" : blah,
...
}
},
"person" : {
id : 33,
...
},
...
]
...
我知道这是不正确的,但我基本上想要
@Projection(name="personRequisiteProjection", types={PersonRequisite.class})
public interface PersonRequisiteProjection {
...
//i know, this would be out of place if it worked but trying to emphasize what i want...
Document getRequisite().getDocument();
//i'd still want Requisite getRequisite() as well but you get what i am after
...
//or more appropriately, force document to show up in Requisite here...
Requisite getRequisite();
...
}
@Projection(name="personRequisiteProjection", types={PersonRequisite.class})
public interface PersonRequisiteProjection {
...
@Value("#{target.requisite.document}")
Document getRequisite().getDocument();
//i'd still want Requisite getRequisite() as well but you get what i am after
...
//or more appropriately, force document to show up in Requisite here...
Requisite getRequisite();
...
}
我经常使用 Spring 存储库接口。一个对我来说工作得很好,但后来我意识到我需要从中得到更多。我想再上一级 get()
我在内部网上工作,因此无法复制和粘贴,但希望以下内容能提供足够的信息使其易于理解...
@Entity
@Table(name="person")
class Person {
...
}
@Entity
@Table(name="requisite")
class Requisite {
...
@OneToOne
@JoinColumn
private Document document;
}
@Entity
@Table(name="person_requisite")
class PersonRequisite {
...
@ManyToOne
@JoinColumn(name="person_id")
private Person person;
...
@ManyToOne
@JoinColumn(name="requisite_id")
private Requisite requisite;
...
}
@Projection(name="personRequisiteProjection", types={PersonRequisite.class})
public interface PersonRequisiteProjection {
...
Person getPerson();
Requisite getRequisite();
...
}
这是我现在得到的结果的表示...
"personRequisites" : [ {
...
"requisite" : {
id : 1,
...
no document object or document id from the requisite
},
"person" : {
id : 33,
...
},
...
]
...
这是我想要的表示...
"personRequisites" : [ {
...
"requisite" : {
id : 1,
...
"document" : {
"id" : 55,
"name" : blah,
...
}
},
"person" : {
id : 33,
...
},
...
]
...
我知道这是不正确的,但我基本上想要
@Projection(name="personRequisiteProjection", types={PersonRequisite.class})
public interface PersonRequisiteProjection {
...
//i know, this would be out of place if it worked but trying to emphasize what i want...
Document getRequisite().getDocument();
//i'd still want Requisite getRequisite() as well but you get what i am after
...
//or more appropriately, force document to show up in Requisite here...
Requisite getRequisite();
...
}
@Projection(name="personRequisiteProjection", types={PersonRequisite.class})
public interface PersonRequisiteProjection {
...
@Value("#{target.requisite.document}")
Document getRequisite().getDocument();
//i'd still want Requisite getRequisite() as well but you get what i am after
...
//or more appropriately, force document to show up in Requisite here...
Requisite getRequisite();
...
}