1、修改maven的pom文件
<build>
<plugins>
<!-- 自动生成代码插件-->
<!-- mybatis generator 自动生成代码插件 -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.7</version>
<configuration>
<configurationFile>src/main/resources/generator/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
2、编写generatorConfig.xml
在IDEA开发环境下,这个文件需要放置在模块的resources的根目录下面
<?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>
<context id="Mysql" targetRuntime="MyBatis3" defaultModelType="flat">
<property name="autoDelimitKeywords" value="true"/>
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<!-- 解决每次都会生成的重复的xml 代码文件 -->
<!--覆盖生成XML文件-->
<plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin" />
<!-- 生成的实体类添加toString()方法 -->
<plugin type="org.mybatis.generator.plugins.ToStringPlugin" />
<!-- 不生成注释 -->
<commentGenerator>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/course?serverTimezone=GMT%2B8"
userId="root"
password="root">
</jdbcConnection>
<!-- domain类的位置 -->
<javaModelGenerator targetProject="src\main\java"
targetPackage="com.course.server.domain"/>
<!-- mapper xml的位置 -->
<sqlMapGenerator targetProject="src\main\resources"
targetPackage="mapper"/>
<!-- mapper类的位置 -->
<javaClientGenerator targetProject="src\main\java"
targetPackage="com.course.server.mapper"
type="XMLMAPPER" />
<!-- <table tableName="test" domainObjectName="Test"/>-->
<!-- <table tableName="chapter" domainObjectName="Chapter"/>-->
<!-- <table tableName="section" domainObjectName="Section"/>-->
<!-- <table tableName="course" domainObjectName="Course"/>-->
<!-- <table tableName="course_content" domainObjectName="CourseContent"/>-->
<!-- <table tableName="course_content_file" domainObjectName="CourseContentFile"/>-->
<!-- <table tableName="teacher" domainObjectName="Teacher"/>-->
<!-- <table tableName="file" domainObjectName="File"/>-->
<!-- <table tableName="user" domainObjectName="User"/>-->
<!-- <table tableName="resource" domainObjectName="Resource"/>-->
<!-- <table tableName="role" domainObjectName="Role"/>-->
<!-- <table tableName="role_resource" domainObjectName="RoleResource"/>-->
<!-- <table tableName="role_user" domainObjectName="RoleUser"/>-->
<!-- <table tableName="member" domainObjectName="Member"/>-->
<!-- <table tableName="sms" domainObjectName="Sms"/>-->
<table tableName="member_course" domainObjectName="MemberCourse"/>
</context>
</generatorConfiguration>
在这个期间出现了
http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd 爆红的情况 查看这个博客解决 博客连接为 : https://www.cnblogs.com/yz-bky/p/12817330.html
3、创建maven运行项
4. 在运行期间出现了 报错情况
mybatis-generator-maven-plugin:1.3.2:generate (default-cli) on project lin: Could not create connect
所以把mysql 的版本改为 8.0.13
这里数据库连接配置中加上serverTimezone=GMT%2B8
来源:oschina
链接:https://my.oschina.net/u/4341956/blog/4297633