我的mybatis-generation的xml文件(名字叫mbg.xml)是这样的:
<!DOCTYPE generatorConfiguration PUBLIC
"-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<context id="DB2Tables" targetRuntime="MyBatis3">
<!-- 生成的pojo,将implements Serializable-->
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>
<!-- 数据源-->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/ssm_crud?useUnicode=true&characterEncoding=utf-8"
userId="root" password="123456"/>
<!-- 异常信息的处理-->
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- 指定Javabean生成的位置-->
<javaModelGenerator targetPackage="com.huishao.beans" targetProject=".\src\main\java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!--指定映射文件的位置-->
<sqlMapGenerator targetPackage="mapper" targetProject=".\src\main\resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!--指定dao接口生成的位置-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.huishao.dao" targetProject=".\src\main\java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<table tableName="tbl_emp" domainObjectName="Employee" />
<table tableName="tbl_dept" domainObjectName="Department"/>
</context>
</generatorConfiguration>
我的主程序:
public class Test1 {
public static void main(String[] args) throws Exception {
List<String> warnings = new ArrayList<String>();
boolean overwrite = true;
File configFile = new File("D:\\disk1\\softdata\\idea-workspace\\SSM\\ssm-crud\\mbg.xml");
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);
}
}
补充:主程序之前在写File configFile = new File()的时候只写的mbg.xml没有写绝对路径,因为我的mbg.xml在工程根目录下,以为程序会找到这个文件,结果就报找不到mbg.xml文件的异常,然后才改成上面的绝对路径。改完之后就报了这个异常:Exception in thread "main" java.sql.SQLException: Column 'IS_GENERATEDCOLUMN' not found.
希望有大神朋友指导,谢谢。