Spring HATEOAS与Spring Data Rest [英] Spring HATEOAS versus Spring Data Rest

查看:100
本文介绍了Spring HATEOAS与Spring Data Rest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是,Spring HATEOAS与Spring Data Rest有什么区别?

Question is, what's the difference between Spring HATEOAS versus Spring Data Rest ?

我觉得两者都可以做同样的事情,而且Spring Data Rest(作为Spring Data的一部分)似乎还活着.

I feel both can do the same, and Spring Data Rest (as part of Spring Data) seems a bit more alive.

https://github.com/spring-projects/spring-hateoas https://github.com/spring-projects/spring-data-rest

您何时会使用其中一个?

When would you use one or the other?

推荐答案

Spring HATEOAS提供了常见的抽象(表示模型,Link类,用于构建指向Spring MVC控制器的链接的API等),以简化构建超媒体驱动的过程通常带有Spring MVC的REST API.因此,您可以将其与Spring MVC一起使用以手动构建那些服务.

Spring HATEOAS provides common abstractions (representational models, a Link class, API to build links pointing to Spring MVC controllers, etc.) to ease building hypermedia driven REST APIs with Spring MVC in general. Thus, you can use it alongside Spring MVC to manually build those services.

Spring Data REST使用Spring HATEOAS为Spring Data存储库管理的实体自动公开资源,并利用超媒体方面进行分页,链接实体等.因此,它涵盖了80%的基本用例,并允许您有选择地添加稍后使用手动实现的控制器来处理更复杂的过程.

Spring Data REST uses Spring HATEOAS to automatically expose resources for entities managed by Spring Data repositories and leverages hypermedia aspects to do pagination, link entities etc. So it covers the 80% use case for the basic stuff and allows you to selectively add more complex processes using manually implemented controllers later on.

要对此有所了解,请随时查看 Spring RESTBucks 示例项目. Order实例的处理完全由Spring Data REST完成(进行一些小的调整以实现业务约束).然后,由于我们实际上需要实施某些步骤和协议以完成订单,因此该流程不属于CRUD类别,因此手动执行了整个付款逻辑.同样,代码是在此处,可以在 speakerdeck.com .

To get a feel for this, feel free to have a look at the Spring RESTBucks sample project. The handling of Order instances is completely done by Spring Data REST (with some minor tweaks to implement business constraints). The entire payment logic is then implemented manually as the process does not fall into the CRUD category as we actually need to implement certain steps and a protocol to complete the order. Again, the code is here, a slide deck with some additional visuals can be found at speakerdeck.com.

这篇关于Spring HATEOAS与Spring Data Rest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆