1.添加依赖:
2.pom文件:
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.3</version>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.2</version>
</dependency>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<configurationFile>src/main/resources/config/generatorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
<dependencies>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>com.zl.slzx</groupId>
<artifactId>slzx-mybatis-generator-plugins</artifactId>
<version>1.0.3-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
3.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="/Users/zl/.m2/repository/mysql/mysql-connector-java/5.1.29/mysql-connector-java-5.1.29.jar"/>
<context id="my" targetRuntime="MyBatis3">
<!-- 生成的Java文件的编码 -->
<!--<property name="javaFileEncoding" value="UTF-8"/>-->
<!-- mybatis 内部插件 -->
<!--<plugin type="org.mybatis.generator.plugins.SqlMapConfigPlugin"></plugin>-->
<!--生成的pojo,将implements Serializable-->
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>
<!--添加mybatis分页插件-->
<plugin type="com.zl.mybatis.generator.plugins.MysqlLimitPlugin"></plugin>
<!--添加逻辑删除插件-->
<plugin type="com.zl.mybatis.generator.plugins.DeleteLogicByIdsPlugin"></plugin>
<!--添加逻辑删除插件-->
<!--<plugin type="com.zl.mybatis.generator.plugins.DeleteLogicByIdPlugin"></plugin>-->
<commentGenerator >
<!--去掉生成日期那行注释;-->
<property name="suppressDate" value="false"/>
<!--去掉所有的注释-->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1:3306/slzx_test"
userId="root"
password="root"/>
<javaModelGenerator targetPackage="com.zl.slzx.core.entity"
targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<sqlMapGenerator targetPackage="com.zl.slzx.core.mapper"
targetProject="src/main/resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<javaClientGenerator targetPackage="com.zl.slzx.core.mapper"
targetProject="src/main/java" type="XMLMAPPER">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<table tableName="lp_zone"
domainObjectName="LpZone"
enableCountByExample="true"
enableUpdateByExample="true"
enableDeleteByExample="true"
enableSelectByExample="true"
selectByExampleQueryId="true">
</table>
</context>
</generatorConfiguration>
4.执行mvn命令:
mybatis-generator:generate