加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – Hibernate逆向工程使用CustomReverseEngineeringStrateg

发布时间:2020-12-15 02:29:44 所属栏目:Java 来源:网络整理
导读:我使用hibernate工具库和ant脚本扩展了org.hibernate.cfg.reveng.DelegatingReverseEngineeringStrategy类,用于自定义逆向工程. 运行ant脚本后,类生成为 – @Entity@Table(name="account",catalog="testdb")public class Account implements java.io.Seriali
我使用hibernate工具库和ant脚本扩展了org.hibernate.cfg.reveng.DelegatingReverseEngineeringStrategy类,用于自定义逆向工程.
运行ant脚本后,类生成为 –

@Entity
@Table(name="account",catalog="testdb"
)

public class Account  implements java.io.Serializable {
}

在上面的类目录中,始终会在生成的类中添加名称.

我试图使用CustomReverseEngineeringStrategy.java类删除目录名称.
这是我的java类 –

public class CustomReverseEngineeringStrategy extends DelegatingReverseEngineeringStrategy {

 public Map<String,MetaAttribute> tableToMetaAttributes(TableIdentifier tableIdentifier){
        Map<String,MetaAttribute> metaAttributes = super.tableToMetaAttributes(tableIdentifier);

        if (metaAttributes == null) {
            metaAttributes = new HashMap<String,MetaAttribute>();
         }

        String catalogName = tableIdentifier.getCatalog();      
        if(metaAttributes.containsKey(catalogName)){
            System.out.print(catalogName);
            metaAttributes.remove(catalogName);         
        }
        return metaAttributes;
    }
}

在此tableIdentifier中返回目录名称.但是,没有方法来设置目录名称.
metaAttributes也不包含目录名称的键.
?我想使用CustomReverseEngineeringStrategy类在类生成过程中删除此目录名称.你能帮帮我吗?

解决方法

我通过使用maven-replacer-plugin修复了这个问题.

也许这不是你要问的,但它确实有效.

<plugin>
        <groupId>com.google.code.maven-replacer-plugin</groupId>
        <artifactId>maven-replacer-plugin</artifactId>
        <version>(version)</version>
        <executions>
            <execution>
                <phase>process-resources</phase>
                <goals>
                    <goal>replace</goal>
                </goals>                    
            </execution>
        </executions>
        <configuration>
            <regex>false</regex>
            <token>,catalog="testdb"</token>
            <value></value>
        </configuration>
    </plugin>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读