mybatis generator 怎么生成配置文件
你是说怎么自动生成实体类,dao等吧
<?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>
<!-- <properties resource="db.properties" /> -->
<classPathEntry location="C:\Users\Administrator\.m2\repository\mysql\mysql-connector-java\5.1.30\mysql-connector-java-5.1.30.jar" />
<context id="mysql2Beans" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 删除代码中带有 代码生成器的注释信息 -->
<property name="suppressAllComments" value="false" />
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressDate" value="true" />
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/****"
userId="root"
password="*****" />
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 生成模型的包名和位置-->
<javaModelGenerator targetPackage="com.shq.pojo" targetProject="d:\gexml">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="com.shq.mapping" targetProject="d:\gexml">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<javaClientGenerator targetPackage="com.shq.dao" targetProject="d:\gexml" type="XMLMAPPER">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
<!--无论字段是什么类型,生成的类属性都是varchar -->
<!-- <table schema="btupayprod" tableName="T_INFO_MARKETING_CFG" enableSelectByExample="false"
enableDeleteByExample="false" enableCountByExample="false" enableUpdateByExample="fasle">
</table> -->
<!-- <columnOverride column="AFTER_AMT" jdbcType="VARCHAR" /> -->
<!-- <table schema="btupayprod" tableName="t_log_online_payment" enableSelectByExample="false"
enableDeleteByExample="false" enableCountByExample="false" enableUpdateByExample="fasle">
无论字段是什么类型,生成的类属性都是varchar <columnOverride column="AFTER_AMT" jdbcType="VARCHAR"
/> </table> -->
<table schema="test" tableName="****" domainObjectName="****" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table schema="test" tableName="****" domainObjectName="****" enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
</table>
<table schema="test" tableName="****" domainObjectName="****" enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
</table>
</context>
</generatorConfiguration>
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
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;
/**
*
*/
/**
* @author Administrator
*
*/
public class MyBatisGeneratorUtils {
public static void main(String[] args) {
try {
System.out.println("start generator ...");
List<String> warnings = new ArrayList<String>();
boolean overwrite = true;
File configFile = new File(MyBatisGeneratorUtils.class.getResource("/generator.xml").getFile());
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
myBatisGenerator.generate(null);
System.out.println("end generator!");
} catch (IOException e) {
e.printStackTrace();
} catch (XMLParserException e) {
e.printStackTrace();
} catch (InvalidConfigurationException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}