Java Spring数据REST查询中返回类型的控件名称
是否可以控制在SpringDataREST中返回搜索结果时使用的类名 我有一个类Java Spring数据REST查询中返回类型的控件名称,java,rest,jackson,spring-data-mongodb,spring-data-rest,Java,Rest,Jackson,Spring Data Mongodb,Spring Data Rest,是否可以控制在SpringDataREST中返回搜索结果时使用的类名 我有一个类Account,它作为JSON模式发布,不包括id字段,因为在RESTful API中这应该是不透明的。为了使用Spring数据MongoDB来持久化这个特性,我用PersistableAccount扩展了Account,它有一个id字段 将搜索结果返回到客户端时,名称persistableAccounts将被公开,这是一个不应泄漏到API中的实现细节: { "_embedded" : { "persis
Account
,它作为JSON模式发布,不包括id
字段,因为在RESTful API中这应该是不透明的。为了使用Spring数据MongoDB来持久化这个特性,我用PersistableAccount
扩展了Account
,它有一个id
字段
将搜索结果返回到客户端时,名称persistableAccounts
将被公开,这是一个不应泄漏到API中的实现细节:
{
"_embedded" : {
"persistableAccounts" : [ {
"lastName" : "McLastName",
"firstName" : "Kevin",
"phoneNumber " : "+44 7700000000",
"email" : "kevin@example.com",
"_links" : {
"self" : {
"href" : "http://localhost:64712/accounts/id"
},
"persistableAccount" : {
"href" : "http://localhost:64712/accounts/id"
}
}
} ]
},
"_links" : {
"self" : {
"href" : "http://localhost:64712/accounts/search/findByFirstName?firstName=Kevin"
}
}
}
是否可以控制使用的术语?如果结果可能包含多个子类型,则Spring数据Rest在响应中始终包含collectionRel 默认情况下,它是类名,但是,您可以在存储库的
@RepositoryRestResource
注释中对其进行自定义
例如:
@RepositoryRestResource(collectionResourceRel = "whateverIwantHere")
public interface CustomerRepository extends CrudRepository<Customer, Long> {
}
@RepositoryRestResource(collectionResourceRel=“whateverIwantHere”)
公共接口CustomerRepository扩展了CrudeRepository{
}
如果结果可能包含多个子类型,则Spring数据Rest在响应中始终包含collectionRel
默认情况下,它是类名,但是,您可以在存储库的@RepositoryRestResource
注释中对其进行自定义
例如:
@RepositoryRestResource(collectionResourceRel = "whateverIwantHere")
public interface CustomerRepository extends CrudRepository<Customer, Long> {
}
@RepositoryRestResource(collectionResourceRel=“whateverIwantHere”)
公共接口CustomerRepository扩展了CrudeRepository{
}
谢谢!我想它的名字应该取自存储库,而不是一般类型。谢谢!我想它的名字应该取自存储库,而不是泛型类型。