`
szqfsx123
  • 浏览: 42361 次
  • 性别: 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是一个集成了众多当前最流行开源框架与工具(包括Hibernate、ibatis、Struts、Spring、DBUnit、Maven、Log4J、Struts Menu、Xdoclet、SiteMesh、OSCache、JUnit、JSTL等(现在还有lucene的,无敌了))于一身的...

    AppFuse

    本文以一个 J2EE 开发者的角度,借助一个简单的应用示例,在融合了个人经验的基础上介绍了如何用 AppFuse 一步步地构建 J2EE 项目。通过阅读本文,读者不仅能够学会用 AppFuse 进行开发,而且能够充分体会到 AppFuse...

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

    本文档详细描述了AppFuse与SpringMVC+mybatis整合的过程,只要你懂一些基本的eclipse操作和基本的maven命令,就可以在三分钟之内迅速的搭建出一个AppFuse的架构

    APPFUSE工具研究.doc

    Appfuse是一个开源的工程应用,它集成了现在最流行的开发框架到该应用中,使用Maven可以很方便的开发和部署因为。也可以集成到现在流行的开源开发工具如eclipse,idea等。现在让我们简单的看看APPFUSE开发应用的简单...

    appfuse1.4-architecture

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

    Appfuse1.9至2.0.2

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

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

    建立项目原型骨架的步骤(最新版本appfuse)appfuse2.1.0-M2 spring3.0 hibernte3.3 struts2.1.8

    AppFuse2.1所需包

    AppFuse2.1所需包,主要包括Spring MVC+Hibernate4 还有一些其它包!

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

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

    SSH学习及开发框架-appfuse

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

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

    NULL 博文链接:https://savagegarden.iteye.com/blog/427169

    Appfuse教程Appfuse开发.pdf

    Appfuse是由Matt Raible开发的一个指导性的入门级J2EE框架,它对如何集成流行的Spring、Hibernate、iBatis、struts、Xdoclet、junit 等基础框架给出了示范。提供了对Taperstry和JSF的支持。  AppFuse是一个集成了...

    appfuse新手上路

    新手使用appfuse2.0,启动步骤和配置过程

    Appfuse框架解析

    Appfuse框架解析,包括登陆验证,执行顺序,加载策略等。

    appfuse 学习笔记

    Appfuse 一个开放源码的项目和应用程序,帮助我们快速而高效的地开发。

    appfuse.tar.gz

    AppFuse - Providing integration and style to open source Java. ----------------------------------------------------------------------------- Developer notes on setting up your IDE to work with ...

    AppFuse项目研究

    Appfuse是由Matt Raible开发的一个指导性的入门级J2EE框架,它对如何集成流行的Spring、Hibernate、iBatis、struts、Xdoclet、junit 等基础框架给出了示范。提供了对Taperstry和JSF的支持

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

    Appfuse是Matt Raible 开发的一个指导性的入门级J2EE框架,它对如何集成流行的Spring、Hibernate、iBatis、Struts、xDcolet、Junit、Taperstry、JSF等基础框架给出了示范。在持久层,AppFuse采用了Hibernate O/R映射...

Global site tag (gtag.js) - Google Analytics