qqjianyue代码工

砌java代码
posts - 62, comments - 9, trackbacks - 0, articles - 10
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

[导入]用appfuse2.0生成一个单独的模块

Posted on 2007-08-30 15:37 Qzi 阅读(631) 评论(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.blogjava.net/liuwentao253/archive/2007/08/30/141406.html

只有注册用户登录后才能发表评论。


网站导航: