环境说明:Windows10、JDK8、ojdbc6-11.2.0.4.jar、mybatis-generator-core-1.3.7.jar
1、在C盘新建autoMybatis文件夹,文件夹中新建generator.xml文件,并将ojdbc6-11.2.0.4.jar 和mybatis-generator-core-1.3.7.jar拷贝至当前文件夹中:
整体截图:
配置文件如下:
<?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>
<!--指定oracle数据库驱动jar-->
<classPathEntry location="ojdbc6-11.2.0.4.jar"/>
<context id="oracle" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 是否去除自动生成的注释 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
<jdbcConnection driverClass="oracle.jdbc.OracleDriver"
connectionURL="jdbc:oracle:thin:@127.0.0.1:1521:orcl"
userId="******"
password="******">
</jdbcConnection>
<!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
NUMERIC 类型解析为java.math.BigDecimal -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- targetProject: 生成实体目录 -->
<javaModelGenerator targetPackage="com.digipwoer.online.entity"
targetProject="C:\autoMybatis\entity">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
<!-- 从数据库返回的值被清理前后的空格 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- targetProject: mapperXml文件目录 -->
<sqlMapGenerator targetPackage="mapper.erms"
targetProject="C:\autoMybatis\mapper">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- targetPackage:mapper文件目录 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.digipower.erms.mapper"
targetProject="C:\autoMybatis\xml">
<property name="enableSubPackages" value="false" />
<property name="rootClass" value="com.digipower.erms.common.model.BaseModel"/>
</javaClientGenerator>
<!-- 指定数据库表 -->
<!--
<table tableName="erms_guide_proj_base_info" domainObjectName="ErmsGuideProjBaseInfo"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table> -->
<table tableName="t_construction_project" domainObjectName="TConstructionProject"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
<table tableName="t_singleproject" domainObjectName="TSingleProject"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
<table tableName="a_single_project" domainObjectName="ASingleProject"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
<table tableName="b_single_project" domainObjectName="BSingleProject"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
<table tableName="c_single_project" domainObjectName="CSingleProject"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
<table tableName="d_single_project" domainObjectName="DSingleProject"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
<table tableName="e_single_project" domainObjectName="ESingleProject"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
<table tableName="f_single_project" domainObjectName="FSingleProject"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
<table tableName="g_single_project" domainObjectName="GSingleProject"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
<table tableName="h_single_project" domainObjectName="HSingleProject"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
<table tableName="i_single_project" domainObjectName="ISingleProject"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
<table tableName="j_single_project" domainObjectName="JSingleProject"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
<table tableName="k_single_project" domainObjectName="KSingleProject"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
<table tableName="l_single_project" domainObjectName="LSingleProject"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
</table>
</context>
</generatorConfiguration>
2、打开CMD命令行,切换到autoMybatis路径下,执行以下命令:
java -jar mybatis-generator-core-1.3.7.jar -configfile generator.xml -overwrite
3、提示错误信息:无法加载Oracle的驱动,
截图待补充:
解决办法:在 generatorConfig.xml
文件中配置<classPathEntry>
元素