2017-11-28 1 views
-1

저는 스프링 저장소 인터페이스를 많이 사용하고 있습니다. 하나는 나를 위해 잘 작동했지만 그때 나는 그것이 조금 더 필요하다는 것을 깨달았다. 나는 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(); 
    ... 
} 
+0

확인하려면이하시기 바랍니다 https://stackoverflow.com/questions/44554979/how-to-loop-and-retrieve-value-from- hateoas-link-attribute-eg-retrieve-a-des/44564464 # 44564464 –

+0

무슨 농담. 봄 투사를 찾는 어린이는 위의 링크로 연결됩니다. 사람들에게 심각한 무언가가 있습니다. 그들은 싫어합니다. 신이 너를 돌볼거야. – user2052618

답변

1
@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(); 
    ... 
} 
+0

이것은 효과가 있습니다! 하나의 사소한 일은 당신이 getRequisite()를 할 수 없다는 것입니다. getDocument()는 무엇이 괜찮은지 알 수 있습니다. 언급 한대로 getDocument()를 문서화하고 주석을 달아 라. 그래서 지금 내 문제는 너무 많은 데이터입니다. Document 객체는 문서의 바이너리를 가지며 다시 돌아옵니다. Value Annotation으로 원하는 문서 조각을 가져와야 할 것입니다. 이것은 단지 우리가 디스크에 문서를 놓아야 함을 보여주고 데이터베이스는 문서에 대한 포인터를 가지고 있습니다. 우리는 이것에 대해 논의했지만 적어도 지금은하지 않을 것이라고 생각했습니다. – user2052618

+0

JsonIgnore를 문서 바이너리가있는 필드에 추가했습니다. 그래서 모든 것이 다시 웅장합니다! 감사! – user2052618

+0

위대한, 당신은 환영합니다 :) –

관련 문제