用appfuse2.0生成一个单独的模块

使用 AppFuse2.0,你需要对 maven有一些基本的了解,比如什么叫 target、什么是 pom.xml 以及如何运行 maven,等等。如果你现在还不知道 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 图


在Appfuse 2.0简单开始和源码的下载中,我简单说明了appfuse2.0的生成

现在我们来生成一个简单的模块 

首先,还是进入dos命令行

在进入myproject里,执行mvn eclipse:eclipse

这是可以在eclipse中import导入appfuse的项目—myproject

在src.main.java.org.appfuse.model中新建一个deparment类

java 代码

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。

xml 代码

1.            <project> 

2.            ... 

3.              <build> 

4.                <plugins> 

5.                  <plugin> 

6.                    <groupId>org.codehaus.mojo</groupId> 

7.                    <artifactId>appfuse-maven-plugin</artifactId> 

8.                    <version>2.0</version> 

9.                    <configuration> 

10.                  <genericCore>true</genericCore> <!-- Set to false if you want Java files generated for your DAOs and Managers --> 

11.                  <fullSource>false</fullSource> <!-- Set to true if you've "full-sourced" your project and changed org.appfuse to your package name --> 

12.                </configuration> 

13.                <dependencies> 

14.                  <dependency> 

15.                    <groupId>${jdbc.groupId}</groupId> 

16.                    <artifactId>${jdbc.artifactId}</artifactId> 

17.                    <version>${jdbc.version}</version> 

18.                  </dependency> 

19.                </dependencies> 

20.              </plugin> 

21.            </plugins> 

22.          </build> 

23.        ... 

24.        </project> 

否则就用 ture ,它可以帮你搞定一切。下面就让我们来运行 “mvn appfuse:gen” 生成代码。

 [input] What is the name of you like to generate code from  POJO (i.e. person)?

Department

在target\appfuse\generated-sources下会生成部门的代码

我们需要接着执行mvn appfuse:install

把生成的代码写入源程序中

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值