导入插件
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<!--该插件用于生成xml、mapper等文件-->
<version>1.3.7</version>
<configuration>
<overwrite>true</overwrite>
</configuration>
</plugin>
在项目的resource目录底下新建generatorConfig.xml文件
generatorConfig.xml文件内容参考
generator配置详解
<!--需要做的修改-->
<!--
1. classPathEntry里location的路径应该为mysql-connector-java-5.1.6.jar所在位置
2. jdbcConnection用于连接数据库,修改对应内容和yml里连接数据库的配置一样
3. javaModelGenerator里targetPackage要修改成存放类的包名,targetProject需修改成目标位置
4. sqlMapGenerator里修改targetPackage和targetProject两项
5. javaClientGenerator里修改targetPackage和targetProject两项
6. 删除原table语句,自己写table语句
-->
<classPathEntry location="D:\LearnMybatis\mysql-connector-java-5.1.6.jar" />
<jdbcConnection
driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1:3306/mall?characterEncoding=utf-8"
userId="root"
password="root">
<javaModelGenerator targetPackage="com.xingshi.mallxs.pojo" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources/">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER" targetPackage="com.xingshi.mallxs.dao" targetProject="src/main.java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!--添加如下语句,不生成注释-->
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!--添加该语句,用于不再追加xml-->
<plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin"></plugin>
执行
<!--在Terminal里输入-->
mvn mybatis-generator:generate