0

我使用 maven 插件生成 pojo 和 dao :

<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<executions>
    <execution>
        <phase>generate-sources</phase>
        <goals>
            <goal>hbm2java</goal>
            <goal>hbm2dao</goal> 
            <goal>hbm2ddl</goal>
        </goals>
    </execution>
</executions>
<configuration>
    <components>
        <component>
            <name>hbm2java</name>
            <implementation>configuration</implementation>
            <outputDirectory>src/main/java</outputDirectory>
        </component>
        <component>
            <name>hbm2dao</name>
            <implementation>configuration</implementation>
            <outputDirectory>src/main/java</outputDirectory>
        </component>
        <component>
            <name>hbm2ddl</name>
            <implementation>configuration</implementation>
            <outputDirectory>src/main/resources/sql</outputDirectory>
        </component>
    </components>
    <componentProperties>
        <jdk5>true</jdk5>
        <format>true</format>
        <configurationfile>src/main/resources/hibernate/hibernate.cfg.xml</configurationfile>

        <drop>true</drop>
        <create>true</create>
        <outputfilename>init.sql</outputfilename>
        <templatepath>src/main/resources/templateftl</templatepath>

    </componentProperties>
</configuration>

糟糕的是,dao 和 pojo 是在同一个包中生成的

在休眠工具中,它是硬编码的

DAOExporter :  setFilePattern("{package-name}/{class-name}Home.java");
POJOExporter : setFilePattern("{package-name}/{class-name}.java");

我觉得它非常难看,我想将 pojo 和 dao 放在不同的包装中,并且不要用“Home”作为 Dao 后缀,而只有“Dao”

您是否知道是否有某种方法可以提供自定义导出器实现或在插件中配置某些东西来实现这一点?

谢谢

4

1 回答 1

0

最后,我使用 JD-gui 反编译并读取插件的代码,并且我设法运行 2 次插件,每次使用不同的模板,目标是 hbmtemplate:一个用于实体,一个用于 dao。

我发现可以通过在 exporterclass 中指定自定义导出器来使用它。maven插件缺少一些xsd之王...

    <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>hibernate3-maven-plugin</artifactId>
    <version>2.2</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <id>genpojo</id>
            <goals>
                <goal>hbmtemplate</goal> 
                <goal>hbm2ddl</goal>
            </goals>
            <configuration>
            <components>
                <component>
                    <name>hbmtemplate</name>
                    <implementation>configuration</implementation>
                    <outputDirectory>src/main/java</outputDirectory>
                </component>                        
                <component>
                    <name>hbm2ddl</name>
                    <implementation>configuration</implementation>
                    <outputDirectory>src/main/resources/sql</outputDirectory>
                </component>
            </components>
            <componentProperties>
                <jdk5>true</jdk5>
                <format>true</format>
                <configurationfile>src/main/resources/hibernate/hibernate.cfg.xml</configurationfile>
                <drop>true</drop>
                <create>true</create>
                <outputfilename>init.sql</outputfilename>
                <templatepath>src/main/resources/templateftl</templatepath>
                <filepattern>{package-name}/pojogen/{class-name}.java</filepattern>
                <template>pojo/Pojo.ftl</template>
            </componentProperties>
        </configuration>
        </execution>
        <execution>
            <phase>generate-sources</phase>
            <id>gendao</id>
            <goals>                         
                <goal>hbmtemplate</goal>
            </goals>
            <configuration>
            <components>                        
                 <component>
                    <name>hbmtemplate</name>
                    <implementation>configuration</implementation>
                    <outputDirectory>src/main/java</outputDirectory>
                </component>
            </components>
            <componentProperties>
                <jdk5>true</jdk5>
                <format>true</format>
                <configurationfile>src/main/resources/hibernate/hibernate.cfg.xml</configurationfile>
                <drop>true</drop>
                <create>true</create>
                <templatepath>src/main/resources/templateftl</templatepath>
                <!--  <exporterclass>com.db.exporter.MyDAOExporter</exporterclass>-->
                <filepattern>{package-name}/daogen/{class-name}Dao.java</filepattern>
                <template>dao/daohome.ftl</template>
            </componentProperties>
        </configuration>
        </execution>
    </executions>

</plugin>
于 2013-12-20T07:41:02.727 回答