jhipster
Jhipster创建应用(单体)
新建目录,打开控制台在此目录下输入:jhipster 命令
INFO! Using JHipster version installed globally
INFO! Executing jhipster:app
██╗ ██╗ ██╗ ████████╗ ███████╗ ██████╗ ████████╗ ████████╗ ███████╗
██║ ██║ ██║ ╚══██╔══╝ ██╔═══██╗ ██╔════╝ ╚══██╔══╝ ██╔═════╝ ██╔═══██╗
██║ ████████║ ██║ ███████╔╝ ╚█████╗ ██║ ██████╗ ███████╔╝
██╗ ██║ ██╔═══██║ ██║ ██╔════╝ ╚═══██╗ ██║ ██╔═══╝ ██╔══██║
╚██████╔╝ ██║ ██║ ████████╗ ██║ ██████╔╝ ██║ ████████╗ ██║ ╚██╗ ╚═════╝ ╚═╝ ╚═╝ ╚═══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══════╝ ╚═╝ ╚═╝
https://www.jhipster.tech
Welcome to JHipster v6.10.5
Application files will be generated in folder: E:\Jhipster\simple-demo
_______________________________________________________________________________________________________________
Documentation for creating an application is at https://www.jhipster.tech/creating-an-app/
If you find JHipster useful, consider sponsoring the project at https://opencollective.com/generator-jhipster
_______________________________________________________________________________________________________________
WARNING! Your Node version is not LTS (Long Term Support), use it at your own risk! JHipster does not support non-LTS releases, so if you encounter a bug, please use a LTS version first.
? May JHipster anonymously report usage statistics to improve the tool over time? Yes
? Which *type* of application would you like to create? Monolithic application (recommended for simple projects)
? [Beta] Do you want to make it reactive with Spring WebFlux? No
? What is the base name of your application? Jhpster_demo
? What is your default Java package name? com.jhipster.demo
? Do you want to use the JHipster Registry to configure, monitor and scale your application? No
? Which *type* of authentication would you like to use? JWT authentication (stateless, with a token)
? Which *type* of database would you like to use? SQL (H2, MySQL, MariaDB, PostgreSQL, Oracle, MSSQL)
? Which *production* database would you like to use? MySQL
? Which *development* database would you like to use? MySQL
? Do you want to use the Spring cache abstraction? Yes, with the Ehcache implementation (local cache, for a single node)
? Do you want to use Hibernate 2nd level cache? No
? Would you like to use Maven or Gradle for building the backend? Maven
? Which other technologies would you like to use?
? Which *Framework* would you like to use for the client? React
? Would you like to use a Bootswatch theme (https://bootswatch.com/)? Default JHipster
? Would you like to enable internationalization support? No
? Besides JUnit and Jest, which testing frameworks would you like to use?
? Would you like to install other generators from the JHipster Marketplace? No
Git repository initialized.
上面的选项大家在新建项目时候是可以选择的,可以自行设置尝试
Jhipster 项目组件
组件 | 功能 |
---|---|
Spring-Security | 认证器 |
Liquibase | 数据库管理 |
Spring Data JPA Repository | ORM框架 |
Spring MVC REST | 控制器 |
Angular路由器,组件和服务 | 默认项目管理后台 |
Swagger-ui | 接口文档 |
其他 | 创建项目时可选 |
Jhipster创建实体
创建实体会生成.jhipster/目录下的json实体映射文件
命令行(适合单表创建)
可以通过运行jhipster entity <entityName> --[options]来调用子生成器。可以通过输入jhipster entity --help找到这些选项的参考。
以下是受支持的选项。
--table-name <table_name> - 默认情况下,JHipster将根据您的实体名称生成一个表名,如果您希望使用其他表名,则可以通过传递此选项来实现。
--angular-suffix <suffix> - 如果您希望所有Angular路由都具有自定义后缀,则可以使用此选项传递该后缀。
--client-root-folder <folder-name> - 指定前端侧实体使用的根文件夹名称。对于富应用和微服务中的网关,默认情况下为空。
--regenerate - 不询问任何问题重新生成现有实体。
--skip-server - -这将跳过服务器端代码,仅生成前端代码。
--skip-client - 这将跳过前端代码,仅生成服务器端代码。
--db - -跳过服务器端生成时,指定的数据库,其他时候无效
E:\Jhipster\simple-demo>jhipster entity User
INFO! Using JHipster version installed globally
INFO! Executing jhipster:entity User
The entity User is being created.
Generating field #1
? Do you want to add a field to your entity? Yes
? What is the name of your field? username
? What is the type of your field? String
? Do you want to add validation rules to your field? No
================= User =================
Fields
username (String)
Generating field #2
? Do you want to add a field to your entity? Yes
? What is the name of your field? password
? What is the type of your field? String
? Do you want to add validation rules to your field? No
================= User =================
Fields
username (String)
password (String)
Generating field #3
? Do you want to add a field to your entity? No
================= User =================
Fields
username (String)
password (String)
Generating relationships to other entities
? Do you want to add a relationship to another entity? No
================= User =================
Fields
username (String)
password (String)
? Do you want to use separate service class for your business logic? Yes, generate a separate service interface and implementation
? Do you want to use a Data Transfer Object (DTO)? No, use the entity directly
? Do you want to add filtering? Dynamic filtering for the entities with JPA Static metamodel
? Is this entity read-only? No
? Do you want pagination on your entity? No
Everything is configured, generating the entity...
Jhipster UML
#安装jhipster-uml
npm install -g jhipster-uml
#生成json实体文件
jhipster-uml <your_file.xmi>
UML Designer编辑器: http://www.umldesigner.org/
JDL Studio
jhipster import-jdl ./my-jdl-file.jdl --json-only
JDL Studio: https://start.jhipster.tech/jdl-studio/
Jhipster生产代码
Jhipster根据每个entity生成代码包含单表的所有增删该差,包括分页动态字段查询。
结语
下篇讲述如何构建微服务