1、在pom中的下的中导入mybatis-generator插件
<!-- mybatis 逆向工程 -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.6</version>
<configuration>
<!-- Mybatis-Generator 工具配置文件的位置 -->
<configurationFile>src/main/resources/mybatis/generatorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
2、导入成功后可以在idea右侧看到mybatis-generator
3、在resources下创建generatorConfig.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:\warehouse\mysql\mysql-connector-java\8.0.19\mysql-connector-java-8.0.19.jar"/>
<context id="mysql" targetRuntime="MyBatis3Simple"
defaultModelType="flat">
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<!-- <plugin type="tk.mybatis.mapper.generator.MapperPlugin"> <property
name="mappers" value="org.zn.mvcbase.mybatis.CommonsMapper" /> </plugin> -->
<commentGenerator>
<property name="suppressAllComments" value="true"/>
<property name="suppressDate" value="true"/>
</commentGenerator>
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/nfshop?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai"
userId="root" password="123456">
<!--MySQL 8.x 需要指定服务器的时区-->
<property name="serverTimezone" value="UTC"/>
<!--MySQL 不支持 schema 或者 catalog 所以需要添加这个-->
<!--参考 : http://www.mybatis.org/generator/usage/mysql.html-->
<property name="nullCatalogMeansCurrent" value="true"/>
<!-- MySQL8默认启用 SSL ,不关闭会有警告-->
<property name="useSSL" value="false"/>
</jdbcConnection>
<!-- po -->
<javaModelGenerator
targetPackage="com.zjj.nfshop.entity"
targetProject="D:\Project\nfshop\src\main\java"
/>
<!--E:\project\fas\fas4\fas-haiot-interface\src\main\java-->
<!--E:\project\fas\fas4\fas-haiot-interface\src\main\resources-->
<!--D:\CodeSpace\Gitee\区级-区域级消防物联网平台\fas4.0-interface\src\main\java-->
<!--D:\CodeSpace\Gitee\区级-区域级消防物联网平台\fas4.0-interface\src\main\resources-->
<!-- mapper -->
<sqlMapGenerator
targetPackage="mybatis.mapper"
targetProject="D:\Project\nfshop\src\main\resources"
/>
<!-- dao -->
<javaClientGenerator
targetPackage="com.zjj.nfshop.mapper"
targetProject="D:\Project\nfshop\src\main\java"
type="ANNOTATEDMAPPER"
/>
<!--生成表数据-->
<table tableName="cart" schema="fas4"
enableCountByExample="true" enableUpdateByExample="true"
enableDeleteByExample="true" enableSelectByExample="true"
selectByExampleQueryId="true">
<property name="useActualColumnNames" value="false"/>
</table>
<table tableName="administrators" schema="fas4"
enableCountByExample="true" enableUpdateByExample="true"
enableDeleteByExample="true" enableSelectByExample="true"
selectByExampleQueryId="true">
<property name="useActualColumnNames" value="false"/>
</table>
<table tableName="good" schema="fas4"
enableCountByExample="true" enableUpdateByExample="true"
enableDeleteByExample="true" enableSelectByExample="true"
selectByExampleQueryId="true">
<property name="useActualColumnNames" value="false"/>
</table>
<table tableName="orders" schema="fas4"
enableCountByExample="true" enableUpdateByExample="true"
enableDeleteByExample="true" enableSelectByExample="true"
selectByExampleQueryId="true">
<property name="useActualColumnNames" value="false"/>
</table>
<table tableName="users" schema="fas4"
enableCountByExample="true" enableUpdateByExample="true"
enableDeleteByExample="true" enableSelectByExample="true"
selectByExampleQueryId="true">
<property name="useActualColumnNames" value="false"/>
</table>
</context>
</generatorConfiguration>
4、双击运行