Entity modeling with JDL

Entity declaration is done using the following syntax:

[<entity javadoc>]
[<entity annotation>*]
entity <entity name> [(<table name>)] {
[<field javadoc>]
[<field annotation>*]
<field name> <field type> [<validation>*]
}

The <entity name> phrase is the name of the entity and will be used for class names and table names. Table names can be overridden using the optional <table name> parameter.

The <field name> phrase is the name of the fields (attributes) you want for the entity and <field type> is the field type, such as string, integer, and so on. Refer to https://www.jhipster.tech/jdl/entities-fields#field-types-and-validations for all supported field types. The ID field will be automatically created and so does not need to be specified in JDL.

The <validation> phrase is optional and one or more <validation> phrases for the fields can be specified depending on the validation supported by the field type. For validations such as max length and pattern, values can be specified in braces.

The <entity javadoc> and <field javadoc> phrases are places where you can add documentation using /** */ syntax to be added to generated Java domain classes.

Multiple annotations can be added to the entity or field using <entity annotation> and <field annotation>. Refer to https://www.jhipster.tech/jdl/options for all available annotations.

An example entity declaration would look like the following:

/**
* This is customer entity Javadoc comment
* @author Foo
*/
@dto(mapstruct)
entity Customer {
/** Name field */
name String required,
age Integer,
address String maxlength(100) pattern(/[a-Z0-9]+/)
}

Enumerations can also be declared using the following syntax:

enum [<enum name>] {
<ENUM KEY> ([<enum value>])
}

Here is an example:

enum Language {
ENGLISH, DUTCH, FRENCH
}

The <enum value> phrase is optional.

Let's learn about relationship management 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
3.134.78.106