pom配置
</dependencies>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>${mybatis.generator.version}</version>
<!-- 仅用于让 Idea generatorConfig.xml 中DTD有效 -->
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>${mybatis.generator.version}</version>
<configuration>
<configurationFile>src/main/resources/generator/generatorConfig.xml</configurationFile>
<!-- If true, then existing Java files will be overwritten if an existing Java file if found with the same name as a generated file.
If not specified, and a Java file already exists with the same name as a generated file,
then MBG will write the newly generated Java file to the proper directory with a unique name (e.g. MyClass.java.1, MyClass.java.2, etc.).
Important: MBG will always merge and overwrite XML files. -->
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<id>Generate MyBatis Artifacts</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>${mybatis.generator.version}</version>
</dependency>
<dependency>
<!-- 用于自定义注释的,还有优化空间,后续可自己实现一个 -->
<groupId>com.github.hellorocky</groupId>
<artifactId>mbg-plugin</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
generatorConfig.xml配置
路径:resources/generator/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="application.properties"/>-->
<!-- <classPathEntry-->
<!-- location="C:/Oracle/Middleware/wlserver_10.3/server/lib/ojdbc6.jar"/>-->
<context id="my" defaultModelType="flat" targetRuntime="MyBatis3" >
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<commentGenerator type="com.github.hellorocky.DatabaseCommentGenerator">
<property name="javaFileEncoding" value="UTF-8"/>
<property name="suppressDate" value="true"/>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1:3306/member?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai"
userId="root"
password="Chf123456">
<property name="useInformationSchema" value="true" />
<!--MySQL 8.x 需要指定服务器的时区-->
<property name="serverTimezone" value="UTC"/>
<!--MySQL 不支持 schema 或者 catalog 所以需要添加这个-->
<!--参考 : http://www.mybatis.org/generator/usage/mysql.html-->
<property name="nullCatalogMeansCurrent" value="true"/>
<!-- MySQL8默认启用 SSL ,不关闭会有警告-->
<property name="useSSL" value="false"/>
</jdbcConnection>
<javaModelGenerator targetPackage="com.hb.member.entity"
targetProject="src/main/java">
<property name="enableSubPackages" value="false"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<sqlMapGenerator targetPackage="sqlmap"
targetProject="src/main/resources">
<property name="enableSubPackages" value="false"/>
</sqlMapGenerator>
<javaClientGenerator targetPackage="com.hb.member.dao"
targetProject="src/main/java" type="XMLMAPPER">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<table
tableName="user"
domainObjectName="UserDO"
mapperName="UserDAO"
enableInsert="true"
enableSelectByPrimaryKey="true"
enableSelectByExample="false"
enableCountByExample="false"
enableUpdateByPrimaryKey="true"
enableUpdateByExample="false"
enableDeleteByPrimaryKey="true"
enableDeleteByExample="false"
>
<!-- generatedKey用于生成生成主键的方法 -->
<generatedKey identity="true" column="user_id" sqlStatement="SELECT LAST_INSERT_ID()"/>
<!--<columnRenamingRule searchString="^D_"
replaceString=""/>-->
</table>
</context>
</generatorConfiguration>
网友评论