创建实体 官方英文

JHipster通过 entity sub-generator 自动创建前后端相应代码

JHipster entity sub-generator 根据项目类型,和选项,自动创建相应代码(gateway和Monolithic application 会创建前后端代码,uaa,microservice创建后端代码)

对于关联关系可以参加 管理实体间映射关系

对于简单(字段少),实体类数量少的实体创建,建议使用命令行,打开项目文件夹

yo jhipster:entity <实体类名> [options] 可以通过yo jhipster:entity --help 查看支持的选项

yo jhipster:entity --help
Usage:
  yo jhipster:entity [options] <name>

Options:
  -h,   --help            # Print the generator's options and usage(打印生成器支持的选项)
        --skip-cache      # Do not remember prompt answers(不记住之前选项,默认记住)                        Default: false
        --skip-install    # Do not automatically install dependencies(不自动安装依赖项,默认安装)           Default: false
        --regenerate      # Regenerate the entity without presenting an option to update it(重新生成)     Default: false
        --table-name      # Specify table name that will be used by the entity(指定生成的表名)
        --fluent-methods  # Generate fluent methods in entity beans to allow chained object construction  Default: true
        --angular-suffix  # Use a suffix to generate AngularJS routes and files, to avoid name clashes(增加angular文件后缀,防止文件名字冲突)
        --skip-server     # Skip the server-side code generation(不生成服务端代码,默认生成)                 Default: false
        --skip-client     # Skip the client-side code generation(不生成客户端代码,默认生成)                 Default: false

Arguments:
  name    Type: String  Required: true

Description:
    Creates a new JHipster entity: JPA entity, Spring MVC REST controller, AngularJS controller, service and view, all wired up together

Example:
    yo jhipster:entity Foo

    This will create:
        .jhipster.Foo.json
        src/main/java/package/domain/Foo.java
        src/main/java/package/repository/FooRepository.java
        src/main/java/package/web/rest/FooResource.java
        src/main/resources/config/liquibase/changelog/20150128232313_added_entity_Foo.xml
        src/main/webapp/app/entities/foo/foos.html
        src/main/webapp/app/entities/foo/foo-detail.html
        src/main/webapp/app/entities/foo/foo.js
        src/main/webapp/app/entities/foo/foo.controller.js
        src/main/webapp/app/entities/foo/foo-detail.controller.js
        src/main/webapp/app/entities/foo/foo.service.js
        src/test/java/package/web/rest/FooResourceTest.java
        src/main/webapp/i18n/en/foo.json
        src/main/webapp/i18n/fr/foo.json

对于比较复杂的实体(数量多,关系复杂,字段多),建议使用JHipster UMLJDL Studiojhipster ide

例如生成 Author和Book两个实体

命令行

创建author实体类

 yo jhipster:entity author (创建author实体类)

The entity Author is being created.


Generating field #1 (第一个字段)

? Do you want to add a field to your entity? Yes
? What is the name of your field? name
? What is the type of your field? String
? Do you want to add validation rules to your field? No

================= Author =================
Fields
name (String)

Generating field #2

? Do you want to add a field to your entity? Yes
? What is the name of your field? birthDate
? What is the type of your field? LocalDate
? Do you want to add validation rules to your field? No

================= Author =================
Fields
name (String)
birthDate (LocalDate)


Generating field #3

? Do you want to add a field to your entity? No (停止创建)

================= Author =================
Fields
name (String)
birthDate (LocalDate)


Generating relationships to other entities

? Do you want to add a relationship to another entity? Yes(创建关联关系)
? What is the name of the other entity? book
? What is the name of the relationship? book
? What is the type of the relationship? one-to-many
? What is the name of this relationship in the other entity? author

================= Author =================
Fields
name (String)
birthDate (LocalDate)

Relationships
book (Book) one-to-many


Generating relationships to other entities

? Do you want to add a relationship to another entity? No

================= Author =================
Fields
name (String)
birthDate (LocalDate)

Relationships
book (Book) one-to-many



? Do you want to use a Data Transfer Object (DTO)? No, use the entity directly (是否创建DTO?)
? Do you want to use separate service class for your business logic? No, the REST controller should use the repository directly (对于业务逻辑是否使用分离的服务类,使用REST controller和repository)
? Do you want pagination on your entity? No(是否分页)

Everything is configured, generating the entity...

   create .jhipster\Author.json
   create src\main\java\com\shunneng\app\domain\Author.java
   create src\main\java\com\shunneng\app\repository\AuthorRepository.java
   create src\main\java\com\shunneng\app\web\rest\AuthorResource.java
 conflict src\main\resources\ehcache.xml
? Overwrite src\main\resources\ehcache.xml? overwrite this and all others
    force src\main\resources\ehcache.xml
   create src\main\resources\config\liquibase\changelog\20160926160804_added_entity_Author.xml
    force src\main\resources\config\liquibase\master.xml
   create src\main\webapp\app\entities\author\authors.html
   create src\main\webapp\app\entities\author\author-detail.html
   create src\main\webapp\app\entities\author\author-dialog.html
   create src\main\webapp\app\entities\author\author-delete-dialog.html
    force src\main\webapp\app\layouts\navbar\navbar.html
   create src\main\webapp\app\entities\author\author.state.js
   create src\main\webapp\app\entities\author\author.controller.js
   create src\main\webapp\app\entities\author\author-dialog.controller.js
   create src\main\webapp\app\entities\author\author-delete-dialog.controller.js
   create src\main\webapp\app\entities\author\author-detail.controller.js
   create src\main\webapp\app\entities\author\author.service.js
   create src\main\webapp\i18n\zh-cn\author.json
    force src\main\webapp\i18n\zh-cn\global.json
   create src\test\javascript\spec\app\entities\author\author-detail.controller.spec.js
   create src\test\javascript\e2e\entities\author.js
   create src\test\java\com\shunneng\app\web\rest\AuthorResourceIntTest.java
   create src\test\gatling\simulations\AuthorGatlingTest.scala

Running gulp Inject to add javascript to index

创建Book实体类

基本同上,不重复贴代码了

JDL Studio

需要遵循 JDL 语言规范

管理实体间映射关系

JHipster IDE

results matching ""

    No results matching ""