Ibatis代码自动生成工具—Abator应用

一.配置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>
        <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" 
			connectionURL="jdbc:oracle:thin:@127.0.0.1:1521:dbtest" userId="bijian" password="123">
        <classPathEntry location="C:\Oracle\wlserver_10.3\server\lib\ojdbc6.jar"/>
        <!-- 
        <classPathEntry location="D:\depEnv\eclipse-pas\workspace\bjTest\lib\ojdbc6.jar"/>
        -->
        </jdbcConnection>
        <javaModelGenerator targetPackage="com.bijian.dto" targetProject="D:\test\src\java"/>
        <sqlMapGenerator targetPackage="test" targetProject="D:\test\src\config\biz"/>
        <daoGenerator targetPackage="com.bijian.integration.dao" targetProject="D:\test\src\java" type="SPRING"/>
			<table tableName="zdbj_product"></table>
			<table tableName="zdbj_sale"></table>
			<table tableName="zdbj_user"></table>
    </abatorContext>
</abatorConfiguration>

 

二.编写IbatisRunner.java

package com.bijian.abator;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.apache.ibatis.abator.api.Abator;
import org.apache.ibatis.abator.config.AbatorConfiguration;
import org.apache.ibatis.abator.config.xml.AbatorConfigurationParser;
import org.apache.ibatis.abator.internal.DefaultShellCallback;

public class IbatisRunner {

    public static void main(String[] args) {
        try {
            List<String> warnings = new ArrayList<String>();
            boolean overwrite = true;
            File configFile = new File((IbatisRunner.class.getResource("abatorConfig.xml")).getFile());
            AbatorConfigurationParser cp = new AbatorConfigurationParser(warnings);
            AbatorConfiguration config = cp.parseAbatorConfiguration(configFile);
            DefaultShellCallback callback = new DefaultShellCallback(overwrite);
            Abator ibator = new Abator(config, callback, warnings);
            ibator.generate(null);
            for (String warning : warnings) {
                System.out.println("warning:" + warning);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

 

三.工程目录结构
Ibatis代码自动生成工具—Abator应用_第1张图片
        运行IbatisRunner.java,如没报错,将会在配置目录下看到生成dto、xml、dao层代码。

你可能感兴趣的:(abator,Ibatis代码自动生成)