【发布时间】:2014-09-25 11:06:35
【问题描述】:
基于示例项目https://github.com/jcoig/gs-accessing-data-rest 中的https://spring.io/guides/gs/accessing-data-rest/)我的存储库定义如下:
@RepositoryRestResource
public interface PersonRepository extends PagingAndSortingRepository<Person, Long> {
List<Person> findByLastName(@Param("name") String name);
}
此类定义的存储库可通过http://localhost:8080/persons 获得,响应为:
{
"_links" : {
"self" : {
"href" : "http://localhost:8080/persons{?page,size,sort}",
"templated" : true
},
"search" : {
"href" : "http://localhost:8080/persons/search"
}
},
"_embedded" : {
"persons" : [ {
"firstName" : "John",
"lastName" : "Smith",
"_links" : {
"self" : {
"href" : "http://localhost:8080/persons/1"
}
}
} ]
},
"page" : {
"size" : 20,
"totalElements" : 1,
"totalPages" : 1,
"number" : 0
}
}
我不想在 URL 中包含 persons,也不想在返回的 JSON 中包含 persons 作为键。当然,我可以将我的存储库定义如下:
@RepositoryRestResource(collectionResourceRel = "key", path = "path")
public interface PersonRepository extends PagingAndSortingRepository<Person, Long> {
List<Person> findByLastName(@Param("name") String name);
}
但我的问题是如何更改默认 Spring 的行为并获得自定义键和自定义路径提供程序(仅作为示例禁用 s 后缀)。
【问题讨论】:
标签: spring rest spring-data-rest hateoas spring-hateoas