【发布时间】:2017-02-03 13:03:28
【问题描述】:
我想将 HATEAOS 链接与 Controller 和 Repository 上的方法结合起来。
@RepositoryRestController
@ResponseBody
@ExposesResourceFor(Group.class)
@RequestMapping(value = "/api/v2/groups", produces = MediaTypes.HAL_JSON_VALUE)
public class GroupController {
@Resource
private GroupService groupService;
@RequestMapping(value = "/external", method = POST)
public @ResponseBody PersistentEntityResource saveExternalGroup(
@RequestBody Group newGroup,
PersistentEntityResourceAssembler assembler) {
return assembler.toResource(groupService.saveExternalGroup(newGroup));
}
}
存储库:
@RepositoryRestResource(excerptProjection = GroupSummary.class)
public interface GroupDao extends DefaultDao<Group, Long> {
@NotNull
List<Group> findByState(@Nullable GroupState state);
...other methods...
我想实现有可能去 /api/v2/groups 并有链接到 /external。目前,仅返回来自存储库的链接:
"_links": {
"first": {
"href": "http://localhost:8300/api/v2/groups?page=0&size=20"
},
"self": {
"href": "http://localhost:8300/api/v2/groups"
},
"next": {
"href": "http://localhost:8300/api/v2/groups?page=1&size=20"
},
"last": {
"href": "http://localhost:8300/api/v2/groups?page=1&size=20"
},
"profile": {
"href": "http://localhost:8300/api/v2/profile/groups"
},
"search": {
"href": "http://localhost:8300/api/v2/groups/search"
}
},
我应该如何实现上述所有内容以及类似的内容:
"external": {
"href": "http://localhost:8300/api/v2/groups/external"
}
或者“/external”是 POST 有问题吗?如果是这样,请用“method=GET”评论并考虑这个问题。
【问题讨论】:
标签: spring-boot spring-data-rest hateoas spring-hateoas