-
Eclipse安装mybatis-generator插件
image.png - POM插件配置
- 新增mybatis依赖
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.2</version>
</dependency>
- 新增插件依赖
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<!-- mybatis用于生成代码的配置文件 -->
<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
- 配置mybatis-generator配置文件
在src/main/resources/下新增文件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="C:/Program Files (x86)/MySQL/Connector.J 5.1/mysql-connector-java-5.1.41-bin.jar" />
<context id="my" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="false" />
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!-- mysql数据库连接 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1:3306/csdndownloader" userId="root"
password="123456" />
<!-- 生成model实体类文件位置 -->
<javaModelGenerator targetPackage="com.chenyq.bean.dto"
targetProject="wxpay-sdk">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 生成mapper.xml配置文件位置 -->
<sqlMapGenerator targetPackage="com.chenyq.bean.mapping"
targetProject="wxpay-sdk">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 生成mapper接口文件位置 -->
<javaClientGenerator targetPackage="com.chenyq.bean.mapper"
targetProject="wxpay-sdk"
type="XMLMAPPER">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- 需要生成的实体类对应的表名,多个实体类复制多份该配置即可 -->
<table tableName="t_account" domainObjectName="Account"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
<table tableName="t_file" domainObjectName="CSDNFile"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
<table tableName="t_order" domainObjectName="Order"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
</context>
</generatorConfiguration>
- 生成代码
- 在Eclipse中选中generatorConfig.xml右键选中执行
- 执行maven命令:
mvn mybatis-generator:generate
经过测试,插件配置中targetProject在命令行执行时,应当使用src/main/java
网友评论