My xml config sheet as follows;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
<generatorConfiguration>
<classPathEntry location="C:\projects\lib\mybatis\mybatis-generator-core-1.3.2.jar" />
<context id="MySQLTables" targetRuntime="MyBatis3">
<!-- ???? ???? ?? ?? -->
<commentGenerator>
<property name="suppressAllComments" value="true" />
<property name="suppressDate" value="true" />
</commentGenerator>
<!-- ?????? ???? -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
password="jeremie">
</jdbcConnection>
<!-- ????? ?? ??? ??? ?? ???? ?? -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- ????? ????? ?? ???? ?? ?? -->
<javaModelGenerator targetPackage="ldg.mybatis.model" targetProject="mybatis_generator">
<!--property name="constructorBased" value="true" />
<property name="immutable" value="true" /-->
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- ?? XML? ?? ?? -->
<sqlMapGenerator targetPackage="test.xml" targetProject="\MyBatis Gen\src">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- ?? XML? ?? ????? ?? ??, type?? ANNOTATEDMAPPER, MIXEDMAPPER, XMLMAPPER ? ?? -->
<javaClientGenerator type="XMLMAPPER" targetPackage="test.dao"
targetProject="\MyBatis Gen\src">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- ???? ??? ?? -->
<table schema="null" tableName="organization" domainObjectName="Comment">
<property name="useActualColumnNames" value="false" />
<property name="ignoreQualifiersAtRuntime" value="true" />
<generatedKey column="comment_no" sqlStatement="MySql" identity="true" type="post" />
<!--columnOverride column="DATE_FIELD" property="startDate" />
<ignoreColumn column="FRED" />
<columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" / -->
</table>
</context>
</generatorConfiguration>
My code as follows;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mybatis.gen;
import com.sun.corba.se.impl.orb.ORBConfiguratorImpl;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.security.auth.login.Configuration;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;
import org.mybatis.generator.internal.util.ClassloaderUtility;
/**
*
* @author carl
*/
public class MyBatisGen {
/**
* @param args the command line arguments
*/
public static void main(String[] args)throws IOException, XMLParserException, InvalidConfigurationException, SQLException, InterruptedException, IllegalArgumentException{
try {
ArrayList<String> warnings = new ArrayList<String>();
File file = new File("mybatisGEN.xml");
System.out.println(file.getCanonicalPath());
boolean overwrite = true;
File configFile = new File("mybatisGEN.xml");
ConfigurationParser cp = new ConfigurationParser(warnings);
org.mybatis.generator.config.Configuration config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
myBatisGenerator.generate(null);
}
catch( Exception ex) {
ex.printStackTrace();
}
}
}