JHipster框架的簡要搭建與說明

JHipster的亮點javascript

  1. 風頭超勁,席捲歐美,最新全能Java Web開發程式產生器 (java web generator)。
  2. 由Java專家累積的開發經驗,配上各種實用的框架技術,去繁取精的運用,全方位的配置,製成出完備的開發應用程式。
  3. 完美Java體系架構,適合各行各業項目,尤爲以適用於面向服務的體系結構(SOA)更爲勝任。
  4. 不論菜鳥,老牛或專家,極容易上手,只要你能夠下載及創建如下要求的工做環境。
  5. 快速建成一個製做就緒的基本項目工做模版,令你能夠用有限的精力專一業務上的運做。
  6. 使用技術:jHipster3.8+Spring4.2.6+Spring Boot1.3.5+Hibernate4.3.11+MySQL5.7.12+AngularJs1.5.8

JHipster或者稱Java Hipster,是一個應用代碼產生器,可以建立Spring Boot + AngularJS的應用。開源項目地址:JHipster/Githubcss

JHipster使用Node.js和Yeoman產生Java應用代碼,使用Maven(Gradle)運行產生的代碼,產生代碼有以下關鍵特徵:html

  • src/main/java 目錄有Spring Boot 配置類在config包中,JHipster使用Spring的Java 配置,沒有XML配置。
  • JPA實體或MongoDB文檔類是在domain包. JPA實體使用緩存和auto-generated 主鍵配置. 若是你使用JHipster產生你的JPA實體, 能夠建立1:N和N:N關係。
  • 在repostiory包中是Spring Data 倉儲.
  • 可選,你有一般@Service-beans 在服務層. 這些服務一般是配置爲事務的 安全的業務對象。
  • REST 端點存在web.rest 包中, 支持Spring MVC的REST
  • JHipster也產生 Liquibase 改變日誌文件,用來處理數據庫更新,增長一個實體將建立特定的schema更新,這將會版本化,當應用重啓時可被執行。
  • 集成Spring的 Test 上下文測試支持.
  • JHipster 建立完整可用的AngularJS 前端,使用CRUD來管理你產生的實體。

 

 

客戶端技術棧前端

單頁面Web應用:java

  • 響應式頁面設計
  • HTML5 Boilerplate
  • Twitter Bootstrap
  • AngularJS
  • 兼容 IE9+ 和其餘現代瀏覽器
  • 完整的國際化支持,基於 Angular Translate
  • 可選 Sass 用於 CSS 設計
  • 可選 Spring Websocket 來實現 WebSocket

強大的 Yeoman 開發工做流:node

  • 使用 Bower 能夠輕鬆的安裝 JavaScript 類庫
  • 使用 Gulp.js 構建, 優化項目, 支持 live reload
  • 使用 Karma and PhantomJS 進行測試

那麼,若是單頁面應用不能知足你的需求呢?git

  • 支持 Thymeleaf 模板引擎, 用於在服務端渲染頁面

 

服務端技術棧github

一個完整的 Spring 應用:web

  • Spring Boot 用於簡化應用配置
  • Maven 或者 Gradle 用於構建,測試和運行應用
  • "development" 和 "production" 配置文件 (支持 Maven 和 Gradle)
  • Spring Security
  • Spring MVC REST + Jackson
  • 可選的 WebSocket 支持 -- 基於 Spring Websocket
  • Spring Data JPA + Bean 驗證
  • 使用 Liquibase 實現數據庫自動更新
  • Elasticsearch 支持對數據庫的搜索功能
  • 支持像MongoDB 這樣的 document-oriented NoSQL 數據庫
  • 支持像Cassandra 這樣的 column-oriented NoSQL 數據庫

支持生產環境:spring

  • Monitoring with Metrics 監控運行狀態
  • 支持 ehcache (本地緩存) 或者 hazelcast (分佈式緩存)
  • 可選的 HTTP session 集羣 -- 基於 hazelcast
  • 優化的靜態資源(gzip filter, HTTP cache headers)
  • 日誌管理 Logback, 可在運行時配置
  • HikariCP 鏈接池,用於性能優化
  • 能夠將應用構建成一個標準的 WAR 文件或者一個可執行的 JAR 文件

 

安裝

安裝前置條件

  1. 全局安裝 Yeoman : npm install -g yo
  2. 全局安裝 Bower:npm install -g bower
  3. 全局安裝 Gulp :npm install -g gulp-cli
  4. 全局安裝 JHipster:npm install -g generator-jhipster

假如已經安裝完畢則軟件各版本以下

  • yo@1.8.5
  • bower@1.7.9
  • gulp-cli@1.2.2
  • npm@3.10.3
  • generator-jhipster@3.8.0

至此,JHipster已經安裝完畢

 

準備工做安裝phantomjs

注意先確保已經設置好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/

感謝您的閱讀。若是文章對您有用,那麼請輕輕點個贊,以資鼓勵。

相關文章
相關標籤/搜索