官网
https://mybatis.org/generator/
配置
mybatis springboot 依赖
<!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
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>
<!--导入属性配置-->
<properties resource="generator-config.properties"/>
<!-- 数据库驱动位置 -->
<classPathEntry location="${location.driverLocation}" />
<context id="DB2Tables" targetRuntime="MyBatis3">
<!-- 配置生成toString()方法 -->
<plugin type="org.mybatis.generator.plugins.ToStringPlugin" />
<commentGenerator>
<!-- 去掉生成日期那行注释 -->
<property name="suppressDate" value="false"/>
<!-- 去掉所有注释 -->
<property name="suppressAllComments" value="true"/>
<!-- 是否添加字段注释 -->
<property name="addRemarkComments" value="true" />
</commentGenerator>
<!-- 数据库连接信息 -->
<jdbcConnection driverClass="${db.driver}"
connectionURL="${db.url}"
userId="${db.user}"
password="${db.pwd}">
</jdbcConnection>
<!-- default false Java type resolver will always use java.math.BigDecimal if the database column is of type DECIMAL or NUMERIC. -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 生成的实体类存放位置 -->
<javaModelGenerator targetPackage="${package.model}" targetProject="./src/main/java/">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 生成映射文件存放位置 -->
<sqlMapGenerator targetPackage="${package.mapper}" targetProject="./src/main/java/">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 生成dao接口存放位置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="${package.mapper}" targetProject="./src/main/java/">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- 生成对应表及类名 -->
<table tableName="" domainObjectName=""
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
</context>
<!-- 运行方法:在eclipse 中,选择pom.xml文件,击右键先择Run AS——>Maven Build… ——>在Goals框中输入:mybatis-generator:generate 或者命令行输入 mvn mybatis-generator:generate
-->
</generatorConfiguration>
generator-config.properties
location.driverLocation=
db.url=jdbc:postgresql://
db.driver=org.postgresql.Driver
db.user=
db.pwd=
package.model=
package.sql=
package.mapper=
pom.xml
<!-- mybatis自动生成插件 -->
<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<verbose>true</verbose><!-- 进度消息是否打印到控制台 -->
<overwrite>false</overwrite><!-- 重新生成是否覆盖 -->
</configuration>
</plugin>
</plugins>
</build>
生成
进项目根目录,pom.xml所在的目录,输入以下命令
mvn mybatis-generator:generate