JHipster的亮點javascript
JHipster或者稱Java Hipster,是一個應用代碼產生器,可以建立Spring Boot + AngularJS的應用。開源項目地址:JHipster/Github。css
JHipster使用Node.js和Yeoman產生Java應用代碼,使用Maven(Gradle)運行產生的代碼,產生代碼有以下關鍵特徵:html
客戶端技術棧前端
單頁面Web應用:java
強大的 Yeoman 開發工做流:node
那麼,若是單頁面應用不能知足你的需求呢?git
服務端技術棧github
一個完整的 Spring 應用:web
支持生產環境:spring
安裝
安裝前置條件
假如已經安裝完畢則軟件各版本以下
至此,JHipster已經安裝完畢
注意先確保已經設置好PhantomJS環境變量,以Windows爲例,右鍵個人電腦-》屬性-》高級系統設置-》高級-》環境變量-》新建用戶或者系統變量
變量名:PHANTOMJS_HOME
變量值:解壓的phantomjs路徑
修改系統變量path追加
;%PHANTOMJS_HOME%\bin;
生成代碼
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 UML 和JDL Studio
例如生成 Author和Book兩個實體
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
項目結構圖
webapp
├── app - Your application(你的應用)
│ ├── account - User account management UI(用戶帳號管理界面)
│ ├── admin - Administration UI(管理員界面)
│ ├── blocks - Common building blocks like configuration and interceptors(公共構建模塊和攔截器)
│ ├── components - Common components like alerting and form validation(經常使用組件,好比警告組件和驗證組件)
│ ├── entities - Generated entities (more information below)(生成的實體,下面會有介紹)
│ ├── home - Home page(主頁)
│ ├── layouts - Common page layouts like navigation bar and error pages(通用頁面佈局,相似導航條和錯誤頁)
│ ├── services - Common services like authentication and user management(通用服務,相似身份驗證和管理)
│ ├── app.constants.js - Application constants(應用常量)
│ ├── app.module.js - Application modules configuration(應用modules配置)
│ ├── app.state.js - Main application router(應用路由--單頁應用業務經過js控制,沒法簡單經過url控制,故而使用應用路由,詳情請百度)
├── bower_components - Dependencies installed by Bower(經過Bower安裝的依賴)
├── content - Static content(靜態內容)
│ ├── images - Images(圖片)
│ ├── styles - CSS stylesheets(css樣式表)
│ ├── fonts - Font files will be copied here(字體庫)
├── i18n - Translation files(國際化語言文件)
├── scss - Sass style sheet files will be here if you choose the option(若是建立應用選擇了LibSass,則其文件會在這生成)
├── swagger-ui - Swagger UI front-end(SwaggerAPI文檔前段頁面)
├── 404.html - 404 page(404錯誤頁)
├── favicon.ico - Fav icon(網站圖標)
├── index.html - Index page(索引頁)
├── robots.txt - Configuration for bots and Web crawlers(針對搜索引擎爬蟲的配置文件)
使用entity sub-generator自動建立的實體,對應的前段結構以下,例如 foo
webapp
├── app
│ ├── entities
│ ├── foo - CRUD front-end for the Foo entity(Foo實體的前段CRUD代碼)
│ ├── foo.controller.js - Controller for the list page(列表頁面的控制器)
│ ├── foo.service.js - Service which access the Foo REST resource(訪問Foo REST 資源接口的服務)
│ ├── foo.state.js - AngularUI router, which manages routes for this entity(AngularUI路由,管理這個實體的)
│ ├── foo-delete-dialog.controller.js - Controller for the delete dialog pop-up(刪除對話框的控制器)
│ ├── foo-delete-dialog.html - View for the delete dialog pop-up(刪除實體的頁面)
│ ├── foo-detail.controller.js - Controller for the entity details page(實體詳細信息頁控制器)
│ ├── foo-detail.html - View for the entity details page(實體詳細信息頁面)
│ ├── foo-dialog.controller.js - Controller for the create/update dialog pop-up(建立和更新對話框控制器)
│ ├── foo-dialog.html - View for the create/update dialog pop-up(建立和更新頁面)
│ ├── foos.html - View for the list page(列表頁面)
├── i18n - Translation files(國際化語言配置文件)
│ ├── en - English translations(英文翻譯)
│ │ ├── foo.json - English translation of Foo name, fields, ...
│ ├── fr - French translations(法語)
│ │ ├── foo.json - French translation of Foo name, fields, ...
轉載請註明出處!
http://www.cnblogs.com/libingbin/
感謝您的閱讀。若是文章對您有用,那麼請輕輕點個贊,以資鼓勵。