`
szqfsx123
  • 浏览: 43918 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

appfuse

 
阅读更多

appfuse中的插件可以自动根据POJO生成业务层代码,可以省去自己去配置的麻烦。但是默认的template难免会与项目的实际需求有所差异,因为需要调整AMP的模版。

要调整AMP的模版,需要先知道它在哪里:
使用命令:mvn appfuse:copy-templates
导出AMP模版至test/resources/appfuse目录。

此时可以自己去查找需要修改的模版来进行修改。

OK。极大提高生产率。

 

 

 

 

1、生成项目
   mvn archetype:generate -B -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-basic-struts-archetype -DarchetypeVersion=2.1.0 -DgroupId=com.launch.mycar.passport -DartifactId=passport -DarchetypeRepository=http://oss.sonatype.org/content/repositories/appfuse

  备注 DgroupId=com.launch.mycar.passport 主包名
     DartifactId=passport 项目名

    参照 http://appfuse.org/display/APF/AppFuse+QuickStart

2、需要把各自的文件放到下面的目录

   jdbc.properties (D:\passport\src\main\resources)
   hibernate.reveng.xml (D:\passport\src\test\resources)
   hibernate.cfg.xml (D:\passport\src\main\resources)

   把 appfuse 文件放到D:\passport\src\test\resources里面

3、下载源代码


    mvn appfuse:full-source

 

4、根绝数据库新建的表 生成model

    mvn appfuse:gen-model

 

8  生成service dao action

    mvn appfuse:gen -Dentity=OperateLog


9 生成eclipse 项目

   mvn eclipse:eclipse

 

 

jdbc.properties

jdbc.driverClassName=${jdbc.driverClassName}
jdbc.url=${jdbc.url}
jdbc.username=${jdbc.username}
jdbc.password=${jdbc.password}

hibernate.dialect=${hibernate.dialect}
hibernatetool.metadatadialect=org.hibernate.cfg.reveng.dialect.OracleMetaDataDialect
# Needed by Hibernate3 Maven Plugin defined in pom.xml
hibernate.connection.username=${jdbc.username}
hibernate.connection.password=${jdbc.password}
hibernate.connection.url=${jdbc.url}
hibernate.connection.driver_class=${jdbc.driverClassName}

 hibernate.reveng.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering
  SYSTEM "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >

<hibernate-reverse-engineering>
<schema-selection match-schema="PASSPORT"/>
    <type-mapping>
        <!-- jdbc-type is name fom java.sql.Types -->
        <sql-type jdbc-type="VARCHAR" length='1' hibernate-type="java.lang.String"/>
        <!-- length, scale and precision can be used to specify the mapping precisly -->
        <sql-type jdbc-type="NUMERIC" precision='1' hibernate-type="java.lang.Integer"/>
        <!-- the type-mappings are ordered. This mapping will be consulted last,
        thus overriden by the previous one if precision=1 for the column -->
        <sql-type jdbc-type="BIGINT" hibernate-type="java.lang.Integer"/>
        <sql-type jdbc-type="INTEGER" hibernate-type="java.lang.Integer"/>
        <sql-type jdbc-type="NUMERIC" hibernate-type="java.lang.Integer"/>
    </type-mapping>

    <!-- BIN$ is recycle bin tables in Oracle -->
    <table-filter match-name="BIN$.*" exclude="true"/>

    <!-- Exclude AppFuse tables from all catalogs/schemas -->
    <table-filter match-name="manager_user" exclude="true"/>
    <table-filter match-name="role" exclude="true"/>
    <table-filter match-name="manager_user_role" exclude="true"/>
</hibernate-reverse-engineering>

 

 

模板参见下篇日志

 

 

 

 

 

 

 

 

 

 

 

附件:

 

1>
AppFuse has a Maven Plugin that allows you to generate all the code in these tutorials. However, we recommend you complete these tutorials before using it so you're familiar with all the code that's being generated.

One of the nice features of AppFuse 2.x is you no longer need to create a DAO or Manager for type-safe CRUD functionality. You merely need to create Spring bean definitions. This means you should be able to easily develop a front-end without worrying about writing code for the backend (until you need customized functionality of course).

<2>
What the full-source plugin does:

Exports all sources from Subversion into your project. It reads the dao.framework and web.framework properties to determine what you need.
Removes warpath plugin from pom.xml.
Calculates dependencies by reading pom.xml files form the various AppFuse modules. It replaces your dependencies with these new ones. The order of the dependencies added is alphabetical based on groupId.
Reads properties from the root AppFuse pom.xml and adds the ones that don't exist to your project.
Renames packages to match your project's groupId.


If you want to customize the code generation templates (written in FreeMarker), you can copy them
into your project using the following command:
appfuse:copy-templates


<3>
改成:
<sql-type jdbc-type="NUMERIC" hibernate-type="java.lang.Integer"/>
//那么生成的javabean 字段也是Integer

Generates Java classes from existing database tables. If you want to customize the reverse engineering strategy,
 you can modify the default hibernate.reveng.xml and put it in src/test/resources.
 You can also override the location by specifying the "revengfile" property in the <configuration>. For example:

<configuration>
  <componentProperties>
    <revengfile>path/to/hibernate.reveng.xml</revengfile>
  </componentProperties>
  <genericCore>${amp.genericCore}</genericCore>
  <fullSource>${amp.fullSource}</fullSource>
</configuration>

Oracle Users: If you create a custom hibernate.reveng.xml, make sure to capitalize the table names
in
<schema-selection match-schema="MY_SCHEMA_NAME"/>.

You'll also need to add the following line to
your jdbc.properties file:

hibernatetool.metadatadialect=org.hibernate.cfg.reveng.dialect.OracleMetaDataDialect

 

<4>
appfuse:copy-templates: Copies FreeMarker templates for CRUD generation into src/test/resources/appfuse.
These templates can be customized to fit your needs. You can delete the templates you don't customize and
the default templates will be used instead.


<5>在DAO用ibatis时,我遇到的问题
执行: mvn appfuse:full-source
[ERROR] 175002 : svn: PROPFIND request failed on '/svn/appfuse~svn/tags/APPFUSE_2.1.0/data/ibatis/src'
解决:
<groupId>org.appfuse.plugins</groupId>
                <artifactId>appfuse-maven-plugin</artifactId>
                <version>${appfuse.version}</version>
                <configuration>
                    <genericCore>${amp.genericCore}</genericCore>
                    <fullSource>${amp.fullSource}</fullSource>
                      <trunk>https://svn.java.net/svn/appfuse~svn/</trunk>
                </configuration>
即添加:
  <trunk>https://svn.java.net/svn/appfuse~svn/</trunk>

保留上面配置执行: mvn appfuse:copy-templates
 svn: PROPFIND request failed on '/svn/appfuse~svn/tags/APPFUSE_2.1.0/plugins/appfuse-maven-plugin/src/main/resources/appfuse/dao'
解决:
删除<trunk>https://svn.java.net/svn/appfuse~svn/</trunk>


<6> 环境:ibatis + oracle
[INFO] Preparing appfuse:gen-model
[INFO] [native2ascii:native2ascii {execution: native2ascii-utf8}]
[INFO] [native2ascii:native2ascii {execution: native2ascii-8859_1}]
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 42 resources
[INFO] Copying 16 resources
[INFO] Copying 8 resources
[INFO] Copying 16 resources
[INFO] Copying 16 resources
[WARNING] POM for 'org.apache.ibatis:ibatis-sqlmap:pom:${ibatis.version}:compile' i
Its dependencies (if any) will NOT be available to the current build.
[INFO] [appfuse:gen-model {execution: default-cli}]
[INFO] Writing 'hibernate.reveng.xml' to target\test-classes\hibernate.reveng.xml \\可见model的产生需要借助
hibernate.reveng.xml

<7>
HibernateException: Could not parse configuration: file:/D:/mavenTest/MyProj/src/main/resources/hibernate.cfg.xml
Caused by: org.dom4j.DocumentException: Connection timed out: connect Nested exception: Connection timed out: connect
        at org.dom4j.io.SAXReader.read(SAXReader.java:484)
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1518)
        解决:
<!-- NOTE: If you're working offline, you might have to change the DOCTYPE to the following:
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">-->
   


《8》
[INFO] Request to merge when 'filtering' is not identical

解决:

      <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-eclipse-plugin</artifactId>
              <version>2.6</version></plugin>  //2.8好像有问题
            <plugin>

<9>
mvn appfuse:gen -Dentiry=Person  会生产Dao,service,..外, 还会生产相应的测试代码.  所以改变template要在这步
操作之前进行


<9>

[INFO] Unable to find resource 'org.codehaus.mojo:mojo-sandbox:pom:2-SNAPSHOT' in repository appfuse-snapshots (http://oss.sonatype.org/content/reposi
tories/appfuse-snapshots)
[INFO] ------------------------------------------------------------------------
原因: 自己不小心去掉了appfuse-maven-plugin <plugin> 的配置

<10.
[ERROR] 175002 : svn: PROPFIND request failed on '/svn/appfuse~svn/!svn/vcc/default'
[ERROR] 175002 : svn: can not read HTTP status line
[INFO] ------------------------------------------------------------------------
原因: 可能是网络问题, 过分吧钟在试

 

《9》
按官方说明来:用ibatis时,把hibernate3-maven-plugin 换成 sql-maven-plugin 出现生成xxxSQL.xml文件错误
如:   <result property="userName" column="userName"/>
 hibernate3-maven-plugin 后:  <result property="userName" column="USER_NAME"/>正确
 
 <10>
 appfuse 代码的自动生成,jpa注解, hibernate3-maven-plugin 视乎不能少;
 hibernate.reveng.xml 映射类型也不能少
 
 
 <11>
 appfuse,oracle,ibatis 时, 生成xxxSQL.xml 日期映射不正确.
 如:  <parameter property="birthdate" jdbcType="varchar" javaType="date"/>
 解决:\MyProj\src\test\resources\appfuse\model\Ejb3PropertyGetAnnotation.ftl
 注释:
  <#-- ${pojo.generateBasicAnnotation(property)} -->

<12>
ERROR freemarker.runtime -
Method public java.lang.String org.hibernate.tool.hbm2x.pojo.EntityPOJOClass.generateJoinColumnsAnnotation
change ${pojo.generateJoinColumnsAnnotation(property)} to ${pojo.generateJoinColumnsAnnotation(property, cfg)} in Ejb3PropertyGetAnnotation.ftl
to have access to ftl files you have to get they with the appropriate goal appfuse:copy-templates
> mvn appfuse:gen-model with a db that as a table with a FK doesn't work


《13>
oracle, 务必要在jdbc.properties加:
hibernatetool.metadatadialect=org.hibernate.cfg.reveng.dialect.OracleMetaDataDialect
否则:hibernate.reveng.xml 设置的属性无法生效

分享到:
评论

相关推荐

    appfuse学习笔记(一)安装部署

    **AppFuse 学习笔记(一):安装与部署** AppFuse 是一个开源项目,它提供了一种快速构建企业级 Web 应用程序的方式。它使用了多种流行的技术栈,如 Spring Boot、Hibernate、Thymeleaf 和 Maven,使得开发者可以更...

    AppFuse

    ### AppFuse:加速J2EE项目开发 #### 一、简介与背景 AppFuse是一个用于启动J2EE项目的工具包,它提供了一种快速而简便的方法来构建基于Java的应用程序。该工具包由Matt Raible创建,他在网络开发领域拥有丰富的...

    AppFuse入门文档(AppFuse与SpringMVC+mybatis整合)

    ### AppFuse与SpringMVC+MyBatis整合详解 #### 一、概述 AppFuse是一个开源的应用程序骨架,主要用于快速构建基于Java的企业级应用。它提供了丰富的模板和配置,能够帮助开发者快速搭建起一个完整的应用架构。本...

    APPFUSE工具研究.doc

    AppFuse 是一个基于Java平台的开源项目,旨在加速和简化Web应用程序的开发。它通过集成各种流行框架,如Struts、Spring、Hibernate等,提供了一个项目骨架,使得开发者能够快速搭建新项目的结构。AppFuse分为1.x和...

    AppFuse学习笔记(J2EE入门级框架)

    【AppFuse 框架详解】 AppFuse 是一个由 Matt Raible 创建的开源项目,它为初学者提供了一个基础的 J2EE 框架,用于演示如何集成多个流行的技术,如 Spring、Hibernate、iBatis、Struts、xDcolet、JUnit、Taperstry...

    可直接使用的appfuse项目

    AppFuse是一个集成了众多当前最流行开源框架与工具(包括Hibernate、ibatis、Struts、Spring、DBUnit、Maven、Log4J、Struts Menu、Xdoclet、SiteMesh、OSCache、JUnit、JSTL等(现在还有lucene的,无敌了))于一身的...

    建立项目原型骨架的步骤(最新版本appfuse)appfuse2.1.0-M2

    AppFuse 是一个开源项目,它提供了快速开发Java Web应用程序的基础框架。这个框架集成了Spring、Hibernate和Struts等主流技术,使得开发者能够迅速构建出符合MVC架构的应用。在最新的版本2.1.0-M2中,AppFuse 提供了...

    AppFuse2.1所需包

    AppFuse 是一个开源项目,旨在简化Java Web应用程序的开发。它提供了一个基础架构,开发者可以在此基础上快速构建安全、可扩展的应用程序。AppFuse 2.1 版本是该项目的一个较早版本,但仍然包含了现代Web开发的核心...

    基于AppFuse框架的B2C电子商务系统研究与实现

    AppFuse是一个开源项目,旨在简化Java Web应用的开发。它提供了一个基础结构,开发者可以在此基础上快速构建安全、模块化的应用程序。本项目是关于利用AppFuse框架构建B2C(Business-to-Consumer)电子商务系统的...

    Appfuse开发教程

    **Appfuse开发教程** Appfuse 是一个开源项目,它提供了一种快速开发Web应用程序的方式,尤其在使用Java技术栈时。本教程将深入探讨如何利用Appfuse创建数据访问对象(DAO)和简单Java对象(POJO),并进行数据库...

    AppFuse项目研究

    AppFuse 是一个由 Matt Raible 创建的开源项目,旨在为初学者提供一个快速入门的 J2EE 框架模板。它集成了多种流行的技术,包括 Spring、Hibernate、iBatis、Struts、Xdoclet 和 JUnit,同时也支持 Taperstry 和 JSF...

    appfuse1.4-architecture

    06年时的appfuse,学习SSH架构的经典入门框架。相对比较老的资料,可以欣赏一下当时的架构,向牛人致敬

    Appfuse1.9至2.0.2

    主要是自己从网络上搜集的一些关于appfuse1.8.2-2.0.2的一些相关资料,间或有点自己试验的记录,还有点maven和quartz的东东,之前我主要是用1.8.2构建项目,感觉还不错,希望对想学习appfuse的人有些帮助.

    MAVEN 搭建APPFUSE

    【MAVEN 搭建APPFUSE】是一个关于使用Maven构建基于AppFuse的应用程序的教程。AppFuse是一个开源项目,旨在简化Web应用程序的开发,它提供了一个基础框架,可以帮助开发者快速启动新项目,整合了Spring、Hibernate、...

    appfuse新手上路

    ### AppFuse 2.0 新手上路:启动与配置全解析 #### 一、环境搭建:JDK、Maven与MySQL准备 对于初次接触AppFuse 2.0的新手而言,首要任务是确保开发环境的正确搭建。这包括Java Development Kit(JDK)5或以上版本...

    SSH学习及开发框架-appfuse

    appfuse 有struts2+hibernate+spring的整合 springmvc+hibernate+spring的整合 多模块,但模块都有 学习开发参考使用非常方便 可以到官方下载最新版的,我只是把自己下载的打包整理一下 注意哈,都是基于maven的...

Global site tag (gtag.js) - Google Analytics