1. Download plugin go idea-mybatis-generator;
2. Write down the file name in the resource 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="E:\mysql-connector-java-8.0.17.jar"/> <context id="testTables" targetRuntime="MyBatis3"> <commentGenerator> <!-- 是否去除自动生成的注释 true:是 : false:否 --> <property name= "suppressAllComments" value = "to true" /> </ commentGenerator > <-! database connections: driver class, connection address, user name, password, -> <-! <JdbcConnection driverClass = "$ {JDBC. } Driver " -> <-! the connectionURL =" $ {jdbc.url} " -> <-! the userId =" $ {jdbc.username} " -> <-! password =" $ {JDBC } .password "> -> ! <- </ JdbcConnection> -> < JdbcConnection driverClass =" com.mysql.cj.jdbc.Driver " the connectionURL =" JDBC:mysql://127.0.0.1:3306/panpan?serverTimezone=UTC" userId="root" password = "" > </ JdbcConnection > <-! default false, the JDBC DECIMAL and NUMERIC type resolution as Integer, when the true JDBC DECIMAL and NUMERIC type resolution is java.math.BigDecimal -> < javaTypeResolver > < Property name = "forceBigDecimals" value = "to false" /> </ javaTypeResolver > <-! targetProject: generating location PO class -> < javaModelGenerator targetPackage = "cn.ljaer.ssm.po" targetProject = "the src \ main \ the Java " > <! -enableSubPackages: whether to allow schema package as a suffix -> < Property name = "enableSubPackages" value = "false" /> <-! returned from the database value spaces before and after being cleaned -> < Property name = "trimStrings" value = "to true" /> </ javaModelGenerator > <-! targetProject: Mapper mapping file generated position -> < sqlMapGenerator targetPackage = "cn.ljaer.ssm.mapper" targetProject = "the src \ main \ Resources" > < ! - enableSubPackages:Whether to allow schema as the package suffix -> <property name="enableSubPackages" value="false"/> </sqlMapGenerator> <!-- targetPackage:mapper接口生成的位置 --> <javaClientGenerator type="XMLMAPPER" targetPackage="cn.ljaer.ssm.mapper" targetProject="src\main\java"> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false"/> </javaClientGenerator> <->Specifies the database tables<! - Table tableName = "Student" > </ Table > <-! fields specify some java table type <Schema Table = "" tableName = ""> <columnOverride column = "" the javaType = "" /> </ Table> -> </ context > </ generatorConfiguration >
Note: ? This is crucial to be added to the database link back serverTimezone = UTC this vital
3.pom.xml need to increase reliance plug
< Plugin > <-! Mybatis-Generator plug, and for automatically generating Mapper POJOs -> < the groupId > org.mybatis.generator </ the groupId > < the artifactId > MyBatis-Generator-Maven-plugin </ the artifactId > < Version > 1.3.2 </ Version > < the configuration > <-! location of the configuration file must be changed to the location of the configuration file -> < configurationFile > src / main / Resources / generatorConfig.xml </ configurationFile > <verbose>true</verbose> <overwrite>true</overwrite> </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>1.3.2</version> </dependency> </dependencies> </plugin>
4. Click carry out this plug-in to generate a map file you want