REST 和 JAVA JPA
我试图理解一些没有正确记录的项目的代码。我是唯一从事该任务的开发人员。我没有太多经验。 有一个数据模型,并且有一些类可以访问它。有人提到数据模型上面有一些剩余的 api。但是当我看到代码时,我可以看到 gette
r 代码这会对某些 uri 进行一些休息调用。 但我查看了 setter
方法,它有普通的 jpa 用于保存对象。 ex extitymanger.persist(objname).
现在是否可以使用 REST 接口来获取数据并使用 JPA 来持久化数据?
I am trying to understand the code of some project which is not properly documented.Am the only developer working on the task.I dont have much experience.
There is a data model and there are some classes witten to access it.It was mentioned that the data model has some rest api on top of it.But when i see the code i can see gette
r code which makes some rest call to some uri.
But i look at setter
methods it has plain jpa used to persisit the object. ex extitymanger.persist(objname).
Now is it possible to use REST interface for getting the data and using JPA to persiste the data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
可以使用 JPA 来执行所有其余操作。您可以查看我发布到我的博客上的示例:
It is possible to use JPA for all the rest operations. You can check out an example I posted to my blog:
是的,这是可能的。如果不了解更多,就不可能知道它是否有效。我的直觉告诉我这不是最好的解决方案。
Yes, it is possible. Without knowing more it is not possible to know if it is effective. My instincts tell me it is not the best solution.
这绝对是可能的。听起来访问类正在围绕数据库进行抽象以进行存储。因此,它的行为类似于 DAO 并使用 JPA 来访问数据源。对于 getter,您的访问类正在使用某些服务中公开的 REST 接口。因此,它不是使用 JPA 来查询和返回数据,而是使用执行相同任务的服务。
也许 REST 接口只是一个获取接口,不提供存储数据的机制,这就是使用直接 JPA 的原因。
That's definitely possible. It sounds like the access classes are abstracting around a database for storage. Thus it's behaving like a DAO and using JPA to access the datasource. For the getters your access class is using an exposed REST interface from some service. So rather than using JPA to query and return the data, it's using a service that's performing the same tasks.
Maybe the REST interface is a get only and doesn't provide a mechanism for storing data and that's why the direct JPA is used.
我认为最好的办法就是忘记尝试计算各个代码片段并专注于大局。计算出所有的输入和所有的输出。甚至编写一些测试用例来测试各种输入创建各种输出。
这样您就可以理解代码的作用,而无需了解所有次要细节。
I think the best thing to do is to forget trying to work out the individual pieces of code and focus on the big picture. Work out all of the inputs and all of the outputs. Even write some test cases to test various inputs create various outputs.
That way you can understand what the code does without needing to know all of the minor ddetails.