appfuse3 生成代码

appfuse3  maven ,hibernate   ,由数据库表生成对应的代码; 

1   代码生成的一些命令 : 

mvn appfuse:gen-model  根据数据库中建立的表结构生成对应的pojo类; 

    注: Foreign Keys  对于有外键的情况,需要我们下在代码生成的模板,进行如下的修改,在进行生成对应的pojo; 
If you have tables with foreign key ift's necessary to alter the template src/test/resources/appfuse/model/Ejb3PropertyGetAnnotation.ftl
        <#lt/>${pojo.generateJoinColumnsAnnotation(property, cfg)} instead of
        <#lt/>${pojo.generateJoinColumnsAnnotation(property)}
to generate @ManyToOne anotations 
(It's necessary to do mvn appfuse:copy-templates first)

   mvn appfuse:gen -Dentity=Name 或 mvn appfuse:gen  根据生成的pojo 生成对应的Dao,Service,Controller类;
   注: 对于后面的命令在进行时,会提示输入对应的Pojo的名称; 
       直接跟pojo的名称会生成默认的包结构的代码;我们可以输入全路径的方式进行生成我们对应路径的代码; 
       The default package name is ${groupId}.model.Name. 
       If you want to generate your code in a sub-package, specify a full package name 
       like -Dentity=com.myproject.subpackage.model.Name or -Dentity=~.subpackage.model.Name. The tilde is a shortcut for ${groupId}.
  
   mvn appfuse:remove -Dentity=Name  : 删除生成的代码
   其他注意: 在我们直接下载的APF的代码中,代码的生成默认是生成通用的DAO和Manager的,我们需要通过修改POM中的amp.genericCore ,改为false这样就可以生成具体的Dao,Manager了
   By default the generated code makes use of the GenericDao and GenericManager. If you do not want this add this to your pom file:
   <amp.genericCore>false</amp.genericCore>

2   appfuse 的俩种架构情况; 

先说下俩个情况,对于maven的架构不同,例如使用 在一起的,即是 web,core在一个工程中; 

对于这种情况的在进行代码生成时可以直接在项目的根路径下进行执行就可以; 

还有是并行model 的,这样我们的Eclipse是有三个工程的,看起来是一个主的项目,一个core ,一个web 的,但是在存储的磁盘上是在一块的; 

        这样在执行amp的命令时,需要在core和web下分别进行执行操作; 对于自定义的代码模板同样要执行俩次; 

3   其他

以mvn  appfuse:gen-model      为例子:

对于在一块的好弄,直接在项目的根目录中使用: mvn  appfuse:gen-model  OK执行成功;  

对于不在一起的,在根下总是报错,找不到jdbc.properties的错误 , 拿到源码发现:

        if (getComponentProperty("configurationfile") == null) {
            // look for jdbc.properties and set "propertyfile" to its path
            File jdbcProperties = new File("target/classes/jdbc.properties");
            if (!jdbcProperties.exists()) {
                jdbcProperties = new File("target/test-classes/jdbc.properties");
            }
            if (jdbcProperties.exists()) {
                if (getComponentProperty("propertyfile") == null) {
                    getComponentProperties().put("propertyfile", jdbcProperties.getPath());
                    getLog().debug("Set propertyfile to '" + jdbcProperties.getPath() + "'");
                }
            } else {
                throw new MojoFailureException("Failed to find jdbc.properties in classpath.");
            }
        }

就不能在该目录下了,需要移到web所在的目录下,target下面的配置文件全的哦, 运行 mvn  appfuse:gen-model      可以的。 

这样执行完毕后,在进行执行 mvn appfuse:gen 选择生成的pojo 就可以完成了web中的代码生成了;


同样到core下面就可以对 core的相关的代码进行生成; 
同样进行执行下; 



代码生成从oracle表生成代码 : 从oracle生成代码时会扫描所表,崩溃。。。。如下除了一些warn ,倒是没有所有的进行扫描

A : 在jdbc中要指定如下方法 : 

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

B: 代码生成时一般会生成 hibernate.reveng.xml 

内容一般如下: 

<hibernate-reverse-engineering>

    <type-mapping>
        <!-- jdbc-type is name fom java.sql.Types -->
        <sql-type jdbc-type="VARCHAR" length='1' hibernate-type="yes_no"/>
        <!-- length, scale and precision can be used to specify the mapping precisly -->
        <sql-type jdbc-type="NUMERIC" precision='1' hibernate-type="boolean"/>
        <!-- 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.Long"/>
        <sql-type jdbc-type="INTEGER" hibernate-type="java.lang.Long"/>
        <sql-type jdbc-type="NUMERIC" hibernate-type="java.lang.Long"/>
    </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="app_user" exclude="true"/>
    <table-filter match-name="role" exclude="true"/>
    <table-filter match-name="user_role" exclude="true"/>
    
    <!-- 对于oracle指定要生成表,其他数据库可以不进行指定; -->
    <table-filter match-schema="APPFUSE" match-name="TABLE1" exclude="true"/>
    <table-filter match-schema="APPFUSE" match-name="TABLE2" exclude="false"/>  

</hibernate-reverse-engineering>

  红色部分就是我们要指定本次生成代码的表, match-schema  大写 ,  match-name 表名 , exclude 本次是否排除不生成











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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值