1、pom.xml中新增plugin
<plugin><groupId>org.mybatis.generator</groupId><artifactId>mybatis-generator-maven-plugin</artifactId><version>1.3.7</version><configuration><overwrite>true</overwrite></configuration></plugin>
2、新建resources/generatorConfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfigurationPUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN""http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"><generatorConfiguration><!-- windows下路径, D:\downloads\xxx.jar--><classPathEntry location="C:\Users\Administrator\Desktop\mysql-connector-java-5.1.6.jar" /><context id="DB2Tables" targetRuntime="MyBatis3"><!-- 不再追加xml内容--><plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin" /><commentGenerator><property name="suppressAllComments" value="true"/></commentGenerator><jdbcConnection driverClass="com.mysql.jdbc.Driver"connectionURL="jdbc:mysql://127.0.0.1:3306/mall?characterEncoding=utf-8"userId="root"password=""></jdbcConnection><javaTypeResolver ><property name="forceBigDecimals" value="false" /></javaTypeResolver><javaModelGenerator targetPackage="com.imooc.mall.pojo" targetProject="src/main/java"><property name="enableSubPackages" value="true" /><!-- <property name="trimStrings" value="true" />--></javaModelGenerator><sqlMapGenerator targetPackage="mappers" targetProject="src/main/resources"><property name="enableSubPackages" value="true" /></sqlMapGenerator><javaClientGenerator type="XMLMAPPER" targetPackage="com.imooc.mall.dao" targetProject="src/main/java"><property name="enableSubPackages" value="true" /></javaClientGenerator><!-- <table tableName="mall_order" domainObjectName="Order" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>--><!-- <table tableName="mall_order_item" domainObjectName="OrderItem" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>--><!-- <table tableName="mall_user" domainObjectName="User" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>--><!-- <table tableName="mall_category" domainObjectName="Category" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>--><!-- <table tableName="mall_product" domainObjectName="Product" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false">--><!-- <columnOverride column="detail" jdbcType="VARCHAR" />--><!-- <columnOverride column="sub_images" jdbcType="VARCHAR" />--><!-- </table>--><table tableName="mall_shipping" domainObjectName="Shipping" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/></context>
</generatorConfiguration>
注意:
context 中内容是有顺序的
commentGenerator在前面s
3、idea中的terminal中执行mybatis自动生成命令
mvn mybatis-generator:generate