via 데이터를 통해 JPARepsitory
리포지토리의 REST를 사용하면 일대 다 관계가있는 엔티티가 두 개 있습니다. 내가 http://localhost:8080/api/items/5
전화 나는 그런연관 링크를 통해 액세스 할 때 컨텐츠 객체에 포함 된 엔티티가 스프링 데이터 REST를 갖는 이유는 무엇입니까?
{
// item attributes
"_links": {
"self": {
"href": "http://localhost:8080/api/items/5"
},
"item": {
"href": "http://localhost:8080/api/items/5"
},
"owner": {
"href": "http://localhost:8080/api/items/5/owner"
}
}
}
같은 것을 얻을 때
@Entity
class Owner {
// owner attributes...
@OneToMany
Set<Item> items;
}
및
@Entity
class Item {
// item attributes...
@ManyToOne
Owner owner;
}
셋업은 ID 1 소유자는 ID 5.
와 아이템을 가지고 전화 할 때 http://localhost:8080/api/items/5/owner
가면
http://localhost:8080/api/owners/1
를 호출하는 경우
{
"content": {
// owner attributes
},
"_links": {
"self": {
"href": "http://localhost:8080/api/owners/1"
},
"owner": {
"href": "http://localhost:8080/api/owners/1"
},
"items": {
"href": "http://localhost:8080/api/owners/1/items"
}
}
}
그러나, 나는 뭔가 여기
{
// owner attributes
"_links": {
"self": {
"href": "http://localhost:8080/api/owners/1"
},
"owner": {
"href": "http://localhost:8080/api/owners/1"
},
"items": {
"href": "http://localhost:8080/api/owners/1/items"
}
}
}
처럼, 소유자가 추가 content
에 싸여 수 단수의 연관 자원에서 호출 될 때 객체. 내가 똑같은 표현을 다시 얻을 것 self
HREF를 호출한다면
업데이트
내가 기대 명확하게, 그러나이 경우 나는하지 않습니다. 표준 엔티티 표현을 얻습니다.
제 질문은 이것이 이유가 무엇입니까? 엔티티가 검색된 URI 인 self
href를 가지고 있거나 엔티티가 연관 자원을 통해 리턴 한 엔티티는 엔티티의 항목 자원과 동일한 표현을 가져야합니까? 한마디로
, 내가 http://localhost:8080/api/items/5/owner
를 호출 할 때 나는 두 가지의
{
"content": {
// owner attributes
},
"_links": {
"self": {
"href": "http://localhost:8080/api/items/5/owner"
// ^^^ the URI that was retrieved that will always return this representation
},
"owner": {
"href": "http://localhost:8080/api/owners/1"
// ^^^ the canonical entity URI
},
"items": {
"href": "http://localhost:8080/api/owners/1/items"
}
}
}
또는
{
// owner attributes
"_links": {
"self": {
"href": "http://localhost:8080/api/owners/1"
},
"owner": {
"href": "http://localhost:8080/api/owners/1"
},
"items": {
"href": "http://localhost:8080/api/owners/1/items"
}
}
}
// ^^^ The canonical entity representation (no "content" wrapper)
하지만 혼합을 얻을 것으로 기대한다.
왜 소유자의 URI 대신'http : // localhost : 8080/api/items/5/owner'를 호출할까요? – zeroflagL
저는 Item에서 'merchant' 링크를 사용하고 있습니다. 나는 그 질문을 갱신 할 것이다. – Strengthiness