Reference blog:
For detailed steps: https: //blog.csdn.net/u010358168/article/details/86246351
Detailed profiles:
https://www.cnblogs.com/maanshancss/p/6027999.html
pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.5.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>mybatis</artifactId> <version>0.0.1-SNAPSHOT</version> <name>mybatis</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.0.1</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>5.1.46</scope> </dependency> <! - you need to manually add dependencies -> <! - depend on the use durid connection pool -> < dependency > < the groupId > com.alibaba </ the groupId > < the artifactId > Druid-Spring-Boot-Starter < / the artifactId > < Version > 1.1.1 </ Version > </ dependency > < dependency > < the groupId > org.springframework.boot </ the groupId > <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <!- <->MyBatis Generator automatic code generation widget plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.2</version> <configuration> <configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile> <overwrite>true</overwrite> <verbose>true</ Verbose > </ Configuration > <-! Use configuration database and link dependent mybatis generator core generating Mapper -> < Dependencies > < dependency > < the groupId > MySQL </ the groupId > < the artifactId > MySQL-Connector-Java < / the artifactId > < Version > 5.1.46 </ Version > </ dependency > < dependency > < the groupId > ORG.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.2</version> </dependency> </dependencies> </plugin> </plugins> </build> </project>
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> <context id="DB2Tables" targetRuntime="MyBatis3Simple"> <commentGenerator> <property name="suppressDate" value="true"/> ->whether to remove the automatically generated annotations true: is: false: No<! - < Property name = "suppressAllComments" value = "to true" /> </ commentGenerator > <-! Database link URL, user name, password -> < JdbcConnection driverClass = "com.mysql.jdbc.Driver" connectionURL = "jdbc : MySQL: // localhost:? 3306 / mvctest serverTimezone GMT% 2B8 = " userId =" hu " password =" 123456 " > </ JdbcConnection > ! <- type conversion -> < javaTypeResolver > <! -Whether BigDecimals, false following types can be automatically converted (Long Integer Short etc.) -> < Property name = "forceBigDecimals" value = "to false" /> </ javaTypeResolver > <-! Package name and location of the generated model -> < javaModelGenerator targetPackage = "com.example.mybatis.pojo" targetProject = "the src / main / Java" > < Property name = "enableSubPackages" value = "to true" /> <-! <Property name = "trimStrings" value = "to true" /> -> </ JavaModelGenerator > <-! Package name and location of the map file generated--> <sqlMapGenerator targetPackage="mappers" targetProject="src/main/resources"> <property name="enableSubPackages" value="true"/> </sqlMapGenerator> <!-- 生成DAO的包名和位置 --> <javaClientGenerator type="XMLMAPPER" targetPackage="com.example.mybatis.mapper" targetProject="src/main/java"> <property name="enableSubPackages" value="true"/> </javaClientGenerator> <! - to be generated is tableName table database table or view name domainObjectName entity class name -> < Table tableName = "User" domainObjectName = "the User" > < Property name = "useActualColumnNames" value = " to false " /> <-! database table primary key -> < generatedKey column =" ID " sqlStatement The =" Mysql " Identity =" to true " /> </ table > </ context > </ generatorConfiguration >
Attention to the problem:
If unsuccessful:
The main database is connected version of the problem I have here is the 5.1.34 corresponds mysql5.7.20