qqjianyue代碼工

          砌java代碼
          posts - 62, comments - 9, trackbacks - 0, articles - 10
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          [導入]用appfuse2.0生成一個單獨的模塊

          Posted on 2007-08-30 15:37 Qzi 閱讀(639) 評論(0)  編輯  收藏

          使用 AppFuse2.0,你需要對 maven有一些基本的了解,比如什么叫 target、什么是 pom.xml 以及如何運行 maven,等等。下表列出了本文中用到的也是較為常用的 AppFuse 的 命令:

          命令                                                                 說明
           
          mvn eclipse:eclipse                      生成eclipse的項目的配置文件,用戶可以直接把項目導入到eclipse中
           
          mvn jetty:run-war                         打包并且發布你的應用程序到Jetty, 查看在 http://localhost:8080  
           
           mvn appfuse:gen                         根據pojo生成dao manger action 頁面及他們的test。
           
          mvn appfuse:install                       把生成的源代碼及配置文件寫入到src中
           
          mvn integration-test                      Runs UI tests in Tomcat using Cargo
           
           mvn appfuse:full-source               Converts AppFuse basic projects to full-source with no AppFuse dependencies. Currently does not work with modular archetypes.
           
           mvn appfuse:gen-model           Generates Java classes from database tables.
           

          本文的示例實現對部門信息的增刪查改等基本功能。用 struts 實現表示層,用 Hibernate 開發持久層,用 Spring 提供事務控制等跨模塊服務,并用 Acegi 進行安全管理。本示例只用到一個域模型:department,下面是它的 UML 圖。

          圖 1. Department UML 圖




          現在我們來生成一個簡單的模塊 

          首先,還是進入dos命令行

          在進入myproject里,執行mvn eclipse:eclipse

          這是可以在eclipse中import導入appfuse的項目—myproject

          在src.main.java.org.appfuse.model中新建一個deparment類

          Department.java

          package org.appfuse.model; 

          import java.io.Serializable;
          import javax.persistence.Column;
          import javax.persistence.Entity;
          import javax.persistence.GeneratedValue;
          import javax.persistence.GenerationType;
          import javax.persistence.Id;
          import javax.persistence.Table; 

          @Entity
          @Table(name
          ="department")
          public class Department extends BaseObject implements Serializable {
                 
          private static final long serialVersionUID = 831759222476769186L;
                 
          private Long id;
                 
          private String name;     
                 
          private String description;      

                 @Id @GeneratedValue(strategy
          =GenerationType.AUTO)
                 
          public Long getId() {
                        
          return id;
                 }
           

                 
          public void setId(Long id) {
                        
          this.id = id;
                 }


                 @Column(name
          ="name",nullable=false,length=100)
                 
          public String getName() {
                        
          return name;
                 }
           

                 
          public void setName(String name) {
                        
          this.name = name;
                 }
                 

                 @Column(name
          ="description",nullable=false,length=100)
                 
          public String getDescription() {
                        
          return description;
                 }
           

                 
          public void setDescription(String description) {
                        
          this.description = description;
                 }
           

                 @Override
                 
          public boolean equals(Object o) {
                        
          // TODO Auto-generated method stub
                        return false;
                 }


                 @Override
                 
          public int hashCode() {
                        
          // TODO Auto-generated method stub
                        return 0;
                 }


                 @Override
                 
          public String toString() {
                        
          // TODO Auto-generated method stub
                        return null;
                 }

          }


          我們現在用appfuse提供的appfuse:gen來生成模塊

          AppFuse 制作了一個代碼生成工具 ,他生成的代碼位于 \target\appfuse\ 目錄下面generated-sources內。代碼生成工具可以生成絕大部分我們需要的代碼,比如 dao 類,service 類,菜單、增刪改的 web 頁面、配置文件、樣本數據,等等。

          如果你希望appfuses生成 dao 和 service 類,就在項目根目錄下的pom.xml中,把genericCore屬性設為false。

                      <plugin>
                          
          <groupId>org.codehaus.mojo</groupId>
                          
          <artifactId>appfuse-maven-plugin</artifactId>
                          
          <version>${appfuse.version}</version>
                          
          <configuration>
                              
          <genericCore>${amp.genericCore}</genericCore>
                              
          <fullSource>${amp.fullSource}</fullSource>
                          
          </configuration>
                      
          </plugin>

           Set to false if you want Java files generated for your DAOs and Managers 

          Set to true if you've "full-sourced" your project and changed org.appfuse to your package name

          它可以幫你搞定一切。下面就讓我們來運行 “mvn appfuse:gen” 生成代碼。

           
          在target\appfuse\generated-sources下會生成部門的代碼

          我們需要接著執行mvn appfuse:install 把生成的代碼寫入源程序中 

          接著執行mvn jetty:run-war,在 http://localhost:8080就可以看到程序了 

          appfuse的初始界面 


           



          劉文濤 2007-08-30 15:37 發表評論

          文章來源:http://www.aygfsteel.com/liuwentao253/archive/2007/08/30/141406.html

          只有注冊用戶登錄后才能發表評論。


          網站導航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          主站蜘蛛池模板: 长顺县| 奎屯市| 临猗县| 津市市| 彰化县| 宽甸| 巫溪县| 屯门区| 太湖县| 利津县| 灵川县| 呈贡县| 泸西县| 祥云县| 玛纳斯县| 天镇县| 大同市| 昌吉市| 融水| 灵台县| 临潭县| 湖北省| 洪湖市| 西青区| 于田县| 周至县| 来安县| 越西县| 潍坊市| 疏勒县| 高邮市| 延庆县| 荔浦县| 临洮县| 博白县| 大同市| 准格尔旗| 鸡西市| 鄱阳县| 揭东县| 兴仁县|