Inheritance 如何在使用Spring Boot时为Spring HATEOAS配置自定义RelProvider?
我使用的是派对模式:Inheritance 如何在使用Spring Boot时为Spring HATEOAS配置自定义RelProvider?,inheritance,spring-boot,spring-data-rest,spring-hateoas,rel,Inheritance,Spring Boot,Spring Data Rest,Spring Hateoas,Rel,我使用的是派对模式: @Entity @Inheritance(strategy=...) @JsonTypeInfo(use= JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") @DiscriminatorColumn(name = "type") public abstract class Party { @Column(updatable = false, insertable =
@Entity
@Inheritance(strategy=...)
@JsonTypeInfo(use= JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@DiscriminatorColumn(name = "type")
public abstract class Party {
@Column(updatable = false, insertable = false)
private String type;
...
}
@Entity
public class Individual extends Party {
...
}
@Entity class Organization extends Party {
...
}
Spring数据REST的响应如下:
{
"_embedded": {
"organizations": [
{
"type":"Organization",
"name": "Foo Enterprises",
"_links": {
"self": {
"href": "http://localhost/organization/2"
},
"organization": {
"href": "http://localhost/organization/2"
}
}
}
],
"individuals": [
{
"type":"Individual",
"name": "Neil M",
"_links": {
"self": {
"href": "http://localhost/individual/1"
},
"individual": {
"href": "http://localhost/individual/1"
}
}
}
]
}
}
{
"_embedded": {
"parties": [
{
"type": "Organization",
"name": "Foo Enterprises",
"_links": {
"self": {
"href": "http://localhost/party/2"
},
"organization": {
"href": "http://localhost/party/2"
}
}
},
{
"type": "Individual",
"name": "Neil M",
"_links": {
"self": {
"href": "http://localhost/party/1"
},
"individual": {
"href": "http://localhost/party/1"
}
}
}
]
}
}
但我需要它这样回应:
{
"_embedded": {
"organizations": [
{
"type":"Organization",
"name": "Foo Enterprises",
"_links": {
"self": {
"href": "http://localhost/organization/2"
},
"organization": {
"href": "http://localhost/organization/2"
}
}
}
],
"individuals": [
{
"type":"Individual",
"name": "Neil M",
"_links": {
"self": {
"href": "http://localhost/individual/1"
},
"individual": {
"href": "http://localhost/individual/1"
}
}
}
]
}
}
{
"_embedded": {
"parties": [
{
"type": "Organization",
"name": "Foo Enterprises",
"_links": {
"self": {
"href": "http://localhost/party/2"
},
"organization": {
"href": "http://localhost/party/2"
}
}
},
{
"type": "Individual",
"name": "Neil M",
"_links": {
"self": {
"href": "http://localhost/party/1"
},
"individual": {
"href": "http://localhost/party/1"
}
}
}
]
}
}
为此,我理解我:
但这不起作用。它似乎没有注册,或者注册不正确。看
如何修复此问题?您是否已使用
@exposeSourceFor
从
我有同样的问题,如果你感兴趣的话,我有一个肮脏的解决方案。为子类实现私有存储库,如
@RepositoryRestResource(path = "parties")
interface IndividualRepository extends PagingAndSortingRepository<Individual, Long>{
}
@RepositoryRestResource(path=“双方”)
接口IndividualRepository扩展了分页和排序存储库{
}
希望这能给你一些暂时的缓解 什么控制器类?这是界面上的Spring数据REST,具有@RepositoryRestResource注释