弹簧数据休息与弹簧数据 jpa [英] spring data rest vs spring data jpa

查看:29
本文介绍了弹簧数据休息与弹簧数据 jpa的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过以下问题

什么是与 Spring Data JPA 相比,使用 Spring Data REST 的优势是什么?

它不能完全满足我的需求.我的数据库在 MYSQL 上,我选择了 Spring-Data-JPA 实现.REST 可以给我带来哪些我在简单的 Spring-Data-JPA 中找不到的额外优势?例如,如果明天,我决定实现一个缓存 b/w 我的业务和数据库模块,在这种情况下,我必须编写较少的代码吗?哪个容易配置?哪个更灵活?如何?

It doesn't quite cater to my needs. My DB is on MYSQL, I chose Spring-Data-JPA implementation. What are all the added advantages that REST can give me which I wont find in simple Spring-Data-JPA? For example if tomorrow, I decide to implement a cache b/w my business and Database module, in which case would I have to write lesser code? Which would be easily configurable? Which would be more flexible and how?

此外,如果我在新应用程序中同时使用 REST 和 JPA,我会违反哪些设计原则?

Also, if I am using both REST and JPA in a new application, what design principles do I break?

我期待从架构的角度得到答案.提前致谢.

I am looking forward to the answers from an architecture perspective. Thanks in advance.

推荐答案

基本上我认为你的问题没有完全切中要害.我认为您还没有完全找到穿越春季项目丛林的方式 - 所以我在这里尝试提供一些方向.

Basically I think your question is not completely to the point. I think you have not completely found your way through the spring project jungle - so I try to give a little orientation here.

Spring-data-jpa 是使用 JPA 访问数据的 Spring 方式.您可以在 spring-data-jpa 之上使用 spring-data-rest 来创建一个 REST-API 层,在您的存储库和实体之上没有代码.

Spring-data-jpa is the spring way to access data using JPA. You could use spring-data-rest on top of spring-data-jpa to create a REST-API layer with no code on top of your repositories and entities.

spring-data-rest 能为你做的事情真是太棒了.这是在 JPA 层之上创建 REST API 的最快方法.而且它也是高度可定制的.但我认为它有它的局限性.最显着的弱点是实体和 API 之间的紧密耦合.通常,您希望在这些层之间进行一些解耦.但它是一款很棒的软件.如果您需要快速并希望编写最少的代码,请使用 spring 数据休息.

And what spring-data-rest can do for you is just amazing. It is the fastest way to create a REST API on top of your JPA layer. And it is also highly customizable. But I think it has it's limits. The most significant weakness is the tight coupling between entities and API. Usually you would like to have a little decoupling between these layers. But it is a great piece of software. If you need to be fast and want to write the minimal amount of code go for spring data rest.

spring-data-rest 的 spring 替代方案是使用 spring MVC 直接自行创建 REST API.Spring-data-jpa 仍将用于实现数据访问层.Spring MVC 非常强大,在底层被 spring-data-rest 使用.这使您可以完全控制 REST 层.

A spring alternative to spring-data-rest is using spring MVC directly to create a REST API on your own. Spring-data-jpa would still be used to implement the data access layer. Spring MVC is very powerful and is used by spring-data-rest under the hood. This gives you full control of the REST layer.

我还想提一下 spring HATEOAS - 它只是 spring 之上的一个模块mvc,它为您提供了创建超媒体驱动的 REST API 的工具 - 因此您可以选择 Richardson 成熟度模型 - 它也被 spring-data-rest 内部使用.

I also want to mention spring HATEOAS - it is just a module on top of spring mvc and it gives you the tools to create a hypermedia driven REST API - so you can go for a maturity level 3 of the Richardson Maturity Model - it is also used by spring-data-rest internally.

这篇关于弹簧数据休息与弹簧数据 jpa的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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