一、在pox.xml添加插件
<build> <plugin> <groupId>org.mybatis.generatorgroupId> <artifactId>mybatis-generator-maven-pluginartifactId> <version>1.4.0version> <configuration> <verbose>trueverbose> <overwrite>trueoverwrite> <configurationFile>src/main/resources/generator/generatorConfig.xmlconfigurationFile> configuration> <dependencies> <dependency> <groupId>mysqlgroupId> <artifactId>mysql-connector-javaartifactId> <version>8.0.20version> dependency> dependencies> plugin> plugins>build>
注意generatorConfig.xml的路径,后面需要创建generatorConfig.xml文件
二、创建generatorConfig.xml文件
在resources下创建generator文件夹,在generator文件夹下创建generatorConfig.xml,修改generatorConfig.xml里面的私有部分。
<?xml version="1.0" encoding="UTF-8"?>/span> PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"><generatorConfiguration> <context id="default" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressDate" value="true"/> <property name="suppressAllComments" value="true"/> commentGenerator> <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/guagua?useUnicode=true&characeterEncoding=utf-8&serverTimezone=UTC" userId="root" password="123456">jdbcConnection> <javaTypeResolver> <property name="forceBigDecimals" value="false"/> javaTypeResolver> <javaModelGenerator targetPackage="com.guaguablog.entity" targetProject="src/main/java"> <property name="enableSubPackages" value="false"/> <property name="constructorBased" value="true"/> <property name="trimStrings" value="true"/> <property name="immutable" value="false"/> javaModelGenerator> <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources"> <property name="enableSubPackages" value="false"/> sqlMapGenerator> <javaClientGenerator type="XMLMAPPER" targetPackage="com.guaguablog.dao" targetProject="src/main/java"> <property name="enableSubPackages" value="false"/> javaClientGenerator> <table tableName="sys_config" domainObjectName="SysConfig" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">table> context>generatorConfiguration>
需要注意的部分有,mysql的连接驱动,url,用户,密码,还有生成的entity,dao所在的包名,还有最后的tableName表名和domainObjectName的java类名。