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 设置的属性无法生效

猜你喜欢

转载自szqfsx123.iteye.com/blog/1602374