核心文件 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>
<context id="MysqlContext" targetRuntime="MyBatis3Simple" defaultModelType="flat">
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<!-- 设置生成代码为utf-8 -->
<property name="javaFileEncoding" value="UTF-8" />
<!-- 生成 JavaBean 对象继承 Serializable 类 -->
<plugin type="org.mybatis.generator.plugins.SerializablePlugin" />
<!-- 通用mapper所在目录 -->
<plugin type="tk.mybatis.mapper.generator.MapperPlugin">
<property name="mappers" value="com.ispring.my.mapper.MyMapper"/>
</plugin>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/myrbac"
userId="root"
password="root">
</jdbcConnection>
<!-- 对应生成的pojo所在包 -->
<javaModelGenerator targetPackage="com.ispring.model" targetProject="src/main/java"/>
<!-- 对应生成的mapper所在目录 -->
<sqlMapGenerator targetPackage="mappers" targetProject="src/main/resources"/>
<!-- 配置mapper对应的java映射 -->
<javaClientGenerator targetPackage="com.ispring.mapper" targetProject="src/main/java" type="XMLMAPPER"/>
<!-- 数据库表 -->
<table tableName="sys_user"></table>
</context>
</generatorConfiguration>
propertie属性
<!-- tk.mybatis 自动生成dao,pojo,xml映射文件 -->
<mybatis.version>3.2.5</mybatis.version>
<tk.mybatis.version>3.4.6</tk.mybatis.version>
<persistence.version>1.0</persistence.version>
<jdbc.driver.version>5.1.38</jdbc.driver.version>
<mybatis.generator.version>1.3.5</mybatis.generator.version>
<mapper.plugin>tk.mybatis.mapper.generator.MapperPlugin</mapper.plugin>
<mapper.Mapper>tk.mybatis.mapper.common.Mapper</mapper.Mapper>
mybatis-generator的依赖
<!-- Start: mybatis-generator -->
<!-- start:一般已经配置可以删除 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${jdbc.driver.version}</version>
<scope>runtime</scope>
</dependency>
<!-- end:一般已经配置可以删除 -->
<!-- 通用tk.mybatis依赖 -->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>${tk.mybatis.version}</version>
</dependency>
<!-- End: mybatis-generator -->
mvn专用命令插件
mvn mybatis-generator:generate ->生成pojo mapper mapper.xml
</build>
<pluginManager>
</plugins>
</plugins>
</pluginManager>
</build>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>${mybatis.generator.version}</version>
<configuration>
<configurationFile>generatorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>false</overwrite>
</configuration>
<dependencies>
<!-- mybatis-generator begin -->
<!-- Begin: mybatis依赖 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>${mybatis.version}</version>
</dependency>
<!-- End: mybatis依赖 -->
<!-- 通用tk.mybatis依赖 -->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>${tk.mybatis.version}</version>
</dependency>
<!-- Begin: 数据库依赖包 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${jdbc.driver.version}</version>
<scope>runtime</scope>
</dependency>
<!-- End: 数据库依赖包 -->
<!-- mybatis-generator -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>${mybatis.generator.version}</version>
</dependency>
<!-- mybatis-generator end -->
</dependencies>
</plugin>