DTO, service, and pagination options

JDL also allows us to declare entity-related options easily. Refer to https://www.jhipster.tech/jdl/options for more details. The options that are currently supported are as follows:

  • service: By default, JHipster generates REST resource classes that call the entity repositories directly. This is the simplest option, but in real-world scenarios, we might need a service layer to handle business logic. This option lets us create a service layer with a simple Spring service bean class or with a traditional interface and implementation for the service bean. Possible values are serviceClass and serviceImpl. Choosing the latter will create an interface and implementation, which is preferred by some people.
  • dto:  By default, domain objects are directly used in the REST endpoints that are created, which may not be desirable in some situations, and you might want to use an intermediary DTO to have more control. JHipster lets us generate the DTO layer using Mapstruct (http://mapstruct.org/), an annotation preprocessor library that automatically generates the DTO classes. It is advisable for you to use a service layer when using DTO. A possible value is mapstruct. For more information, visit http://www.jhipster.tech/using-dtos/.
  • filter: This option lets us enable JPA-based filtering capabilities for the entity. This works only when a service layer is used. For more details, visit http://www.jhipster.tech/entities-filtering/.
  • paginate: This option lets us enable pagination for an entity. This enables pagination on the resource layer and also implements a paging option on the client-side. Possible values are no, pagination, and infinite-scroll.
  • noFluentMethod: This lets us disable Fluent-API-styled setters for the generated entity domain objects.
  • skipClient/skipServer: These options let us either skip the client-side or server-side code during generation.
  • angularSuffix: This option lets us specify a suffix for the folder and class names in the frontend code.
  • readOnly: This creates a read-only entity.

The general syntax for option declaration is <OPTION> <ENTITIES | * | all> [with <VALUE>] [except <ENTITIES>]. All of the options can also be used as annotations on the entities.

The following code shows some possible options and the different syntaxes in which they can be declared:

@service(serviceImpl)
entity A
entity B
...
entity Z

dto * with mapstruct
service B with serviceClass
paginate * with pagination except B, C
paginate B, C with infinite-scroll
filter A, B

Let's take a look at the JDL-Studio in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.95.38