将静止的物体从弹跳靴转移到角度的最佳实践是什么

时间:2022-09-11 15:03:26

Considering an application using

考虑一个应用程序使用

  • Spring Boot on server side ( with hibernate, a DAO pattern and an oracle db )
  • 服务器端启动(使用hibernate、DAO模式和oracle db)
  • AngularJS on client side

    AngularJS在客户端

  • REST API to communicate ( Spring REST )

    用于通信的REST API (Spring REST)

What's the most common approach to transfert data ? On my previous project, I Use DTO ( with dozer ), but it's hundred additional classes and waste of development time and I look for a strong alternative.

传输数据最常见的方法是什么?在我之前的项目中,我使用DTO(使用dozer),但是它有上百个额外的类,并且浪费了开发时间,我寻找一个强大的替代方案。

I hear about Jackson ?

我听说了杰克逊?

Create JSON manually ? Made my entity serializable and send them directly ?

手动创建JSON吗?使我的实体可序列化并直接发送?

Update 2018

更新2018

2 years after, I m still using DTO class serialized into json with jackson in all my project, using spring data is not the point here, returning an Entity which is a DB object is not a good practice, you can use @JsonIgnore on some property of your entities but it s not really flexible. You can use the mapper that you want or handmade, MapStruct which is use in the great JHipster project seems a good one.

2年之后,我仍然使用DTO类序列化为json与杰克逊在我所有的项目中,使用spring的数据点,返回一个实体是一个DB对象不是一个好的做法,您可以使用@JsonIgnore一些属性的实体,但它不是很灵活。你可以使用你想要的映射器或者手工制作的MapStruct,它在JHipster项目中使用,看起来不错。

1 个解决方案

#1


2  

You should take a look at Spring Data JPA with Spring Data REST. I use it with angular and it's super easy to expose your business model as Restful Endpoints. You can use Hibernate as a JPA provider. And with Spring Boot you can easily create a project that puts all these together, so you don't have to do anything. It can save you a lot of time.

您应该看看Spring Data JPA和Spring Data REST。我使用它的角度,它非常容易将您的业务模型公开为Restful端点。您可以将Hibernate用作JPA提供者。使用Spring Boot,您可以轻松创建一个将所有这些放在一起的项目,因此您不需要做任何事情。它可以节省你很多时间。

The process is this:

这个过程是这样的:

  1. You create the Entity (Model)
  2. 创建实体(模型)
  3. You create a JpaRepository
  4. 您创建一个JpaRepository

End there you have it. The Restful endpoint is generated.

到此为止吧。生成Restful端点。

In the front end i use Restangular. Also in many cases you can avoid DTO's and use excerpts and projections.

在前端,我使用的是rest。在许多情况下,您可以避免使用DTO,并使用节选和投影。

Read this guide Accessing JPA Data with REST.

阅读本指南,使用REST访问JPA数据。

#1


2  

You should take a look at Spring Data JPA with Spring Data REST. I use it with angular and it's super easy to expose your business model as Restful Endpoints. You can use Hibernate as a JPA provider. And with Spring Boot you can easily create a project that puts all these together, so you don't have to do anything. It can save you a lot of time.

您应该看看Spring Data JPA和Spring Data REST。我使用它的角度,它非常容易将您的业务模型公开为Restful端点。您可以将Hibernate用作JPA提供者。使用Spring Boot,您可以轻松创建一个将所有这些放在一起的项目,因此您不需要做任何事情。它可以节省你很多时间。

The process is this:

这个过程是这样的:

  1. You create the Entity (Model)
  2. 创建实体(模型)
  3. You create a JpaRepository
  4. 您创建一个JpaRepository

End there you have it. The Restful endpoint is generated.

到此为止吧。生成Restful端点。

In the front end i use Restangular. Also in many cases you can avoid DTO's and use excerpts and projections.

在前端,我使用的是rest。在许多情况下,您可以避免使用DTO,并使用节选和投影。

Read this guide Accessing JPA Data with REST.

阅读本指南,使用REST访问JPA数据。