一、配置Maven pom.xml 文件
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
<configurationFile>src/main/resources/mybatis/generator/generatorConfig.xml</configurationFile>
</configuration>
</plugin>
configurationFile 这个指定generatorConfig.xml文件的路径,如果不指定, 插件默认会读到src/main/resources目录下,这个问题搞了我半天,‘
http://mbg.cndocs.tk/running/running.html 这个网址有generator 的详细说明 http://generator.sturgeon.mopaas.com/
配置文件如下范例:
<?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>
<!-- 配置文件路径 -->
<properties resource="properties/generatorConfig.properties"/>
<!--数据库驱动包路径 -->
<classPathEntry location="${drive.class.path}"/>
<context id="MySQLTables" targetRuntime="MyBatis3">
<!--关闭注释 -->
<commentGenerator>
<property name="suppressDate" value="true"/>
</commentGenerator>
<!--数据库连接信息 -->
<jdbcConnection driverClass="${jdbc.driver}" connectionURL="${jdbc.url}" userId="${jdbc.username}"
password="${jdbc.password}">
</jdbcConnection>
<!--生成的model 包路径 -->
<javaModelGenerator targetPackage="${model.package}" targetProject="${target.project}">
<property name="enableSubPackages" value="ture"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!--生成xml mapper文件 路径 -->
<sqlMapGenerator targetPackage="mybatis/mappers" targetProject="src/main/resources">
<property name="enableSubPackages" value="ture"/>
</sqlMapGenerator>
<!-- 生成的Dao接口 的包路径 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="${dao.package}" targetProject="${target.project}">
<property name="enableSubPackages" value="ture"/>
</javaClientGenerator>
<!--对应数据库表名 -->
<table tableName="users">
</table>
</context>
</generatorConfiguration>
generatorConfig.properties"
注意这个文件和路径
#数据库驱动jar
drive.class.path=D:/maven/repository/mysql/mysql-connector-java/5.1.34/mysql-connector-java-5.1.34.jar
#数据库连接参数
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://192.168.0.86:3306/base?useUnicode=true&characterEncoding=utf-8
jdbc.username=root
jdbc.password=root
#包路径配置
model.package=cn.bishiti.base.model
dao.package=cn.bishiti.base.dao
xml.mapper.package=resources\mybatis\mappers
target.project=src/main/java
在eclipse 中,选择pom.xml文件,击右键先择Run AS——>Maven Build… ——>在Goals框中输入:mybatis-generator:generate