IBatis Abator去除注释版

以前曾修改过Abator,增加了中文注释,即字段的中文说明,先有博友提出要求共享!该版本经使用后发现这样做法得不偿失,需要对每个表进行字段的中文注释补入(在配置文件中增加)!而且还有编码的问题,所以废弃了中文注释。现共享的版本,只去除了Abator生成的代码产生的无用注释和生成的文件名不友好问题!建议数据库的设计命名规范使用下划线进行分割,如:表名:user_other,字段名real_name,使用abator生成后的就会变成:userOther,realName的驼峰格式

 

该工具的使用范例,已Netbeans6.1为例

 

1、新建一个abatortool的java工程

 

2、在工程的根目录下新建abatorConfig.xml文件,文件的内容参考如下:

 

     <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE abatorConfiguration PUBLIC "-//Apache Software Foundation//DTD Abator for iBATIS Configuration 1.0//EN"
"http://ibatis.apache.org/dtd/abator-config_1_0.dtd">

<abatorConfiguration>
    <abatorContext id="Tables" generatorSet="Java5">
        <!--
        <jdbcConnection driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver"
                        connectionURL="jdbc:sqlserver://localhost:1433;databaseName=test" userId="sa" password="test">
            <classPathEntry location="E:\NetbeansProjects\abatortool\lib\sqljdbc.jar" />
        </jdbcConnection>
       
        <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
                        connectionURL="jdbc:oracle:thin:@localhost:1521:TEST" userId="test" password="test">
            <classPathEntry location="E:\NetbeansProjects\abatortool\lib\classes12.jar" />
        </jdbcConnection>
        -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/test" userId="root" password="test">
            <classPathEntry location="E:\NetbeansProjects\abatortool\lib\mysql-jdbc-5.1.6.jar" />
        </jdbcConnection>
       
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>
       
        <javaModelGenerator targetPackage="com.test.domain" targetProject="E:\NetbeansProjects\abatortool\src">
            <property name="enableSubPackages" value="true" />
            <property name="trimStrings" value="true" />
        </javaModelGenerator>
       
        <sqlMapGenerator targetPackage="com.test.dao.sql" targetProject="E:\NetbeansProjects\abatortool\src">
            <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>
        <!-- 如果不使用spring,则将type改为IBATIS -->
        <daoGenerator type="SPRING" targetPackage="com.test.dao" targetProject="E:\NetbeansProjects\abatortool\src">
            <property name="enableSubPackages" value="true" />
        </daoGenerator>
        <table tableName="company"/>
        <table tableName="company_other"/>
    </abatorContext>
</abatorConfiguration>

3、修改工程的build.xml,修改后的文件参考如下:

 

     <?xml version="1.0" encoding="UTF-8"?>
<project name="abatortool" default="default" basedir=".">
    
    <property name="generated.source.dir" value="${basedir}" />
   
    <target name="genfiles" description="Generate the files">
        <taskdef name="abator"
                 classname="org.apache.ibatis.abator.ant.AbatorAntTask"
                 classpath="${generated.source.dir}/lib/abator.jar" />
        <abator overwrite="true" configfile="${generated.source.dir}/abatorConfig.xml" verbose="false" >
            <propertyset>
                <propertyref name="generated.source.dir"/>
            </propertyset>
        </abator>
    </target>
   
</project>

4、在工程根目录下新建lib文件夹,将abator.jar和需要的数据库连接和spring的jar放入其中

你可能感兴趣的:(spring,oracle,mysql,ibatis,jdbc)