1, create a Maven project
2, configure MyBatis reverse engineering plug-in pom.xml
<build>
<finalName>mybatis-generator-maven</finalName>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
</plugins>
</build>
3, configuration 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 >
<!-- mysql jar 文件位置 -->
<classPathEntry location="/Point9/MyMaven/maven-repository/mysql/mysql-connector-java/5.1.43/mysql-connector-java-5.1.43.jar" />
<context id="store" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
<!-- 是否去除所有自动生成的文件的时间戳,默认为false -->
<property name="suppressDate" value="true"/>
</commentGenerator>
<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1:3306/myshop"
userId="root"
password="root">
</jdbcConnection>
<!-- targetPackage:包名称(自定义) targetProject:项目路径(自定义) -->
<!--定义model的包名称-->
<javaModelGenerator targetPackage="top.point9.shop.v1.entity" targetProject="src/main/java">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
<!-- 从数据库返回的值被清理前后的空格 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 配置生成相应的实体Mapper.xml,对于Mapper3.X我们需要把type="XMLMAPPER" -->
<!-- targetPackage:包名称(自定义) targetProject:项目路径(自定义) -->
<sqlMapGenerator targetPackage="top.point9.shop.v1.mapper" targetProject="src/main/java">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- 配置生成相应的接口类,对应与Mapper.xml中的一系列CRUD方法SQL语句 -->
<!-- targetPackage:包名称(自定义) targetProject:项目路径(自定义) -->
<javaClientGenerator targetPackage="top.point9.shop.v1.dao" targetProject="src/main/java" type="XMLMAPPER">
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!-- 商品表 -->
<table schema="" tableName="t_product" domainObjectName="Product"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
<!-- 商品详情表 -->
<table schema="" tableName="t_product_desc" domainObjectName="ProductDesc"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
<!-- 商品类别表 -->
<table schema="" tableName="t_product_type" domainObjectName="ProductType"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
</context>
</generatorConfiguration>
4, add a "Run Run" option in the Intellij IDEA, using maven run mybatis-generator-maven-plugin plugin
mybatis-generator:generate -e
Results are as follows:
Original (including source code download) Address: http://www.point9.top/index.php/2019/03/09
2.9 blog www.point9.top
2.9 Forum bbs.point9.top
2.9 E-mail [email protected]
Web full-stack technology exchange
click on the link to join a group chat full stack exchange group [Web]: https://jq.qq.com/?_wv=1027&k=5rnUzsF