【发布时间】:2018-05-12 13:54:29
【问题描述】:
我经常使用 Spring Repository 接口。一个对我来说工作得很好,但后来我意识到我需要更多一点。我想再上一层 get()
我在 Intranet 上工作,因此无法复制和粘贴,但希望以下内容能够提供足够的信息以使其易于理解...
@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();
...
}
【问题讨论】:
-
开什么玩笑。搜索 spring projection child 真的会引导您访问上面的链接吗?人们有严重的问题。他们是仇恨者。上帝会照顾你的。
标签: spring repository projection