Ben*_*nny 8 hateoas spring-data spring-data-jpa spring-data-rest spring-hateoas
我有一个有趣的问题.我的数据模型如下:
A型:
@Entity
@JsonIgnoreProperties(ignoreUnknown = true)
public class A {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
}
Run Code Online (Sandbox Code Playgroud)
B型:
@Entity
@JsonIgnoreProperties(ignoreUnknown = true)
public class B {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
}
Run Code Online (Sandbox Code Playgroud)
嵌入式C:
@Embeddable
@JsonIgnoreProperties(ignoreUnknown = true)
public class C {
@ManyToOne
private A a;
@ManyToOne
private B b;
}
Run Code Online (Sandbox Code Playgroud)
和D型:
@Entity
@JsonIgnoreProperties(ignoreUnknown = true)
public class D {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ElementCollection
@OrderColumn(name = "ORDER_INDEX")
@CollectionTable(
name = "d_c_join",
joinColumns = @JoinColumn(name = "d_id")
)
private List<C> listOfC;
}
Run Code Online (Sandbox Code Playgroud)
反序列化(和存储)实体工作正常.当D类对象被序列化时,结果如下:
{
"_embedded" : {
"ds" : [ {
"id" : 1,
"listOfC" : [ { }, { } ],
"_links" : {
"self" : {
"href" : "http://localhost:8000/ds/1"
}
}
} ]
}
}
Run Code Online (Sandbox Code Playgroud)
如何配置Spring-Data以在C中序列化A和B(最好是通过它们的URI).
我非常肯定您正在寻找的是Projections。我不认为 Spring 不会在没有它的情况下序列化引用的集合。
有关更多详细信息,请参阅我的答案:Spring Data-Rest POST to sub-resource
| 归档时间: |
|
| 查看次数: |
473 次 |
| 最近记录: |