Skip to content

Instantly share code, notes, and snippets.

@0532
Last active October 24, 2016 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0532/5b28f744114b0ec97614 to your computer and use it in GitHub Desktop.
Save 0532/5b28f744114b0ec97614 to your computer and use it in GitHub Desktop.
mybatis自动生成数据库表的dao,mapper类
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<classPathEntry location="/workspace/svn-fbiepss/lib/ojdbc6.jar"/>
<!--信息 -->
<context id="AllInfo" targetRuntime="MyBatis3">
<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
connectionURL="jdbc:oracle:thin:@localhost:1521:orcl"
userId="epss"
password="epss">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<javaModelGenerator targetPackage="epss.repository.model" targetProject="main/java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<sqlMapGenerator targetPackage="epss.repository.mapper" targetProject="main/java">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER" targetPackage="epss.repository.dao" targetProject="main/java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!--业务类例子 -->
<table schema="epss" tableName="es_ctt_info">
<property name="ignoreQualifiersAtRuntime" value="true" />
<generatedKey column="pkid" sqlStatement="select sys_guid() from dual" identity="false"/>
</table>
<table schema="epss" tableName="es_ctt_item">
<property name="ignoreQualifiersAtRuntime" value="true" />
<generatedKey column="pkid" sqlStatement="select sys_guid() from dual" identity="false"/>
</table>
<table schema="epss" tableName="es_item_stl_subctt_eng_m">
<property name="ignoreQualifiersAtRuntime" value="true" />
<generatedKey column="pkid" sqlStatement="select sys_guid() from dual" identity="false"/>
</table>
<table schema="epss" tableName="es_item_stl_subctt_eng_q">
<property name="ignoreQualifiersAtRuntime" value="true" />
<generatedKey column="pkid" sqlStatement="select sys_guid() from dual" identity="false"/>
</table>
<table schema="epss" tableName="es_item_stl_subctt_eng_p">
<property name="ignoreQualifiersAtRuntime" value="true" />
<generatedKey column="pkid" sqlStatement="select sys_guid() from dual" identity="false"/>
</table>
<table schema="epss" tableName="es_item_stl_tkctt_eng_sta">
<property name="ignoreQualifiersAtRuntime" value="true" />
<generatedKey column="pkid" sqlStatement="select sys_guid() from dual" identity="false"/>
</table>
<table schema="epss" tableName="es_item_stl_tkctt_eng_mea">
<property name="ignoreQualifiersAtRuntime" value="true" />
<generatedKey column="pkid" sqlStatement="select sys_guid() from dual" identity="false"/>
</table>
<!--<table schema="epss" tableName="ES_CTT_INFO">
<property name="ignoreQualifiersAtRuntime" value="true" />
<generatedKey column="pkid" sqlStatement="select sys_guid() from dual" identity="false"/>
</table>
<table schema="epss" tableName="es_init_cust">
<property name="ignoreQualifiersAtRuntime" value="true" />
<generatedKey column="pkid" sqlStatement="select sys_guid() from dual" identity="false"/>
</table>
<table schema="epss" tableName="es_init_power">
<property name="ignoreQualifiersAtRuntime" value="true" />
</table>
<table schema="epss" tableName="es_init_power_his">
<property name="ignoreQualifiersAtRuntime" value="true" />
</table>
<table schema="epss" tableName="ES_CTT_ITEM">
<property name="ignoreQualifiersAtRuntime" value="true" />
<generatedKey column="pkid" sqlStatement="select sys_guid() from dual" identity="false"/>
</table>
<table schema="epss" tableName="es_item_info">
<property name="ignoreQualifiersAtRuntime" value="true" />
<generatedKey column="pkid" sqlStatement="select sys_guid() from dual" identity="false"/>
</table>
<table schema="epss" tableName="es_init_stl">
<property name="ignoreQualifiersAtRuntime" value="true" />
<generatedKey column="pkid" sqlStatement="select sys_guid() from dual" identity="false"/>
</table>
<table schema="epss" tableName="es_item_stl_subctt_eng_m">
<property name="ignoreQualifiersAtRuntime" value="true" />
<generatedKey column="pkid" sqlStatement="select sys_guid() from dual" identity="false"/>
</table>
<table schema="epss" tableName="es_item_stl_subctt_eng_q">
<property name="ignoreQualifiersAtRuntime" value="true" />
<generatedKey column="pkid" sqlStatement="select sys_guid() from dual" identity="false"/>
</table>
<table schema="epss" tableName="es_item_stl_subctt_eng_p">
<property name="ignoreQualifiersAtRuntime" value="true" />
<generatedKey column="pkid" sqlStatement="select sys_guid() from dual" identity="false"/>
</table>
<table schema="epss" tableName="es_item_stl_tkctt_eng_sta">
<property name="ignoreQualifiersAtRuntime" value="true" />
<generatedKey column="pkid" sqlStatement="select sys_guid() from dual" identity="false"/>
</table>
<table schema="epss" tableName="es_item_stl_tkctt_eng_mea">
<property name="ignoreQualifiersAtRuntime" value="true" />
<generatedKey column="pkid" sqlStatement="select sys_guid() from dual" identity="false"/>
</table>-->
<!--<table tableName="all_tab_columns"/>-->
</context>
</generatorConfiguration>
package generator;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Ibator {
public static void main(String[] argv){
Ibator ibator = new Ibator();
ibator.run("resources/generatorConfig.xml");
}
public void run(String configfile) {
List<String> warnings = new ArrayList<String>();
boolean overwrite = true;
String path = this.getClass().getResource("").getPath();
File configFile = new File(path + configfile);
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = null;
try {
config = cp.parseConfiguration(configFile);
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (XMLParserException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = null;
try {
myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
try {
myBatisGenerator.generate(null);
} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment