ibatis自動生成コード,abator

2590 ワード

1.まず新規工事を行いabatorを導入する.JArパッケージ
2.建設運行類
 
import java.util.List;

/**
 * User: tofhao
 * Date: 11-6-29
 * Time:  1:58
 */
public class IbatisRunner {
    public static void main(String... strings) {
        try {
            List<String> warnings = new ArrayList<String>();
            boolean overwrite = true;
            
            //Class 
            
            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();
        }
    }
}

3.構成ファイルが同じディレクトリにある
 
<?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:db" userId="dev" password="ev" >
      <classPathEntry location="C:\com\oracle\ojdbc14\10.2.0.4\ojdbc14-10.2.0.4.jar" />
    </jdbcConnection>
    <javaModelGenerator targetPackage="com.jd.modle" targetProject="F:\IdeaProject\IbatisGenerate\src" />
    <sqlMapGenerator targetPackage="com.jd.sqlmap" targetProject="F:\IdeaProject\IbatisGenerate\src" />
    <daoGenerator targetPackage="com.jd.dao" targetProject="F:\IdeaProject\IbatisGenerate\src" type="GENERIC-CI" />
    <table  tableName="order" >
      
    </table>
  </abatorContext>
</abatorConfiguration>