总结了老师以及网上各位大佬的逆向工程,现终于配置出适合自己的一款了。
1.先在网上下载到zip压缩包
2.解压后是这样子的
3.找到解压路径(D:\Reverse Engineering\mybatis-generator-core-1.3.2\lib)下的generator.xml 编辑 编辑结果如下。
<?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="D:\Reverse Engineering\mybatis-generator-core-1.3.2\lib\mysql-connector-5.1.8.jar" />
<context id="testTables" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/crm?characterEncoding=utf-8"
userId="root"
password="123456">
</jdbcConnection>
<!-- oracle的 -->
<!-- <jdbcConnection driverClass="oracle.jdbc.OracleDriver"
connectionURL="jdbc:oracle:thin:@127.0.0.1:1521:yycg"
userId="yycg"
password="yycg">
</jdbcConnection> -->
<!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
NUMERIC 类型解析为java.math.BigDecimal -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- targetProject:生成pojo实体类的位置 暂时还是设置在bin目录下-->
<javaModelGenerator targetPackage="com.qfedu.pojo"
targetProject="D:\Reverse Engineering\mybatis-generator-core-1.3.2\lib">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
<!-- 从数据库返回的值被清理前后的空格 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- targetProject:mapper映射文件生成的位置 如:UserMapper.xml 生成的位置-->
<sqlMapGenerator targetPackage="com.qfedu.mapper"
targetProject="D:\Reverse Engineering\mybatis-generator-core-1.3.2\lib">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- targetPackage: mapper接口生成的位置 如:UserMapper.java生成的位置 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.qfedu.mapper"
targetProject="D:\Reverse Engineering\mybatis-generator-core-1.3.2\lib">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!-- 指定根据数据库到底要生成那些表的
tableName:数据库里需要逆向工程的表名
domainObjectName:将要创建成功的pojo实体类的名字
enableCountByExample:默认false 如果是true的话,会自动创建生成增删改差的方法 不需要,改为false
-->
<table tableName="base_dict" domainObjectName="Dict"
enableCountByExample="false"
enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false">
</table>
<table tableName="customer" domainObjectName="Customer"
enableCountByExample="false"
enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false">
</table>
<table tableName="sys_user" domainObjectName="User"
enableCountByExample="false"
enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false">
</table>
<!-- 有些表的字段需要指定java类型
<table schema="" tableName="">
<columnOverride column="" javaType="" />
</table> -->
</context>
</generatorConfiguration>
需要注意的位置:
javaModelGenerator,生成PO类的位置
sqlMapGenerator,mapper映射文件生成的位置
javaClientGenerator,mapper接口生成的位置
table,指定数据库表
操作的表是这三个
4.双击cmd.exe 复制下边的代码 mysql就粘贴第一句就行 回车
mysqld的: java -jar mybatis.jar -configfile generator.xml -overwrite
orcal的: java -jar mybatis.jar -configfile generatorOracle.xml -overwrite
5.创建完成