1、Eclipse 插件 mybatis.generator
2、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>
</configuration>
</plugin>
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="D:\webdevelop\mavenprofile\mysqlConnector\mysql-connector-java-5.1.42-bin.jar" />
<context id="context1" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/nearby"
userId="root" password="123456" />
<javaModelGenerator targetPackage="com.nearby.dao.mybatis.model"
targetProject="D:\web\workspaceMine\com.nearby\nearby-dao\src\main\java" />
<sqlMapGenerator targetPackage="com.nearby.dao.mybatis.mapping"
targetProject="D:\web\workspaceMine\com.nearby\nearby-dao\src\main\java" />
<javaClientGenerator type="XMLMAPPER" targetPackage="com.nearby.dao.mybatis.dao"
targetProject="D:\web\workspaceMine\com.nearby\nearby-dao\src\main\java">
</javaClientGenerator>
<table tableName="user" domainObjectName="User"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false" >
<property name="useActualColumnNames" value="true"/>
</table>
</context>
</generatorConfiguration>
4、运行
如果是在eclipse 中,选择pom.xml文件,击右键先择Run AS——>Maven Build… ——>在Goals框中输入:mybatis-generator:generate
如果在命令行输入Maven命令即可,注意:一定是当前项目目录下运行该命令:
mvn mybatis-generator:generate