我正在尝试使用spring-hateoas插件来实现超媒体。
我没有像本例中那样的JPA:https://spring.io/blog/2015/09/15/react-js-and-spring-data-rest-part-2-hypermedia
但我真的很喜欢这个结果。唯一的问题是,我不想不使用JPA,我宁愿使用紫丁香。
我看了Greg项目和文档,我仍然不明白如何在我的项目中实现它。
我不打算使用分页,但我没有任何CrudRepository。
发布于 2016-11-01 09:25:38
使用hateoas和JPA的诀窍是,它是开箱即用的。但是,这并不意味着没有JPA就不能创建具有相同仇恨响应的API。您只需创建自己的控制器并手动配置每个响应即可。
如何做这件事有几种方法。关于这个主题,有一个关于Spring的很好的入门教程:https://spring.io/guides/gs/rest-hateoas/
如果您想返回hateoas资源,可以尝试如下所示:
@RequestMapping("/myEntity")
public Resource<MyEntity> getMyEntity(String title) {
MyEntity entity = // load your entity here
// Provide a link to lookup of this resource
Link entityLink = linkTo(MyEntityController).slash('/myEntity').withSelfRel()
return new Resource<MyEntity>(entity, entityLink.expand(entity.entityId))
}https://stackoverflow.com/questions/40342344
复制相似问题