<!--mybatis generator插件-->
<plugin>
<!-- https://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-maven-plugin -->
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.7</version>
<configuration>
<configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
</dependencies>
</plugin>
在src/main/resources/generate 文件夹下创建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>
<!--数据库连接驱动, 可以在这里添加,也可以在pom中添加-->
<!-- <classPathEntry location="file:///media/nianshao/nie475/java/repository/mysql/mysql-connector-java/5.1.47/mysql-connector-java-5.1.47.jar"/>-->
<context id="mybatis" targetRuntime="mybatis3">
<!--生成toString()方法-->
<plugin type="org.mybatis.generator.plugins.ToStringPlugin"/>
<!-- suppressAllComments:**阻止**生成注释,默认为false-->
<!-- suppressDate:**阻止**生成的注释包含时间戳,默认为false-->
<commentGenerator>
<!-- 是否去除自动生成的注释,true 和 false -->
<property name="suppressAllComments" value="true"/>
<property name="suppressDate" value="true"/>
</commentGenerator>
<!-- 数据库参数-->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql:///bookstore?characterEncoding=utf8"
userId="root"
password="123456">
</jdbcConnection>
<!--该属性可以控制是否强制DECIMAL和NUMERIC类型的字段转换为Java类型的java.math.BigDecimal,默认值为false,一般不需要配置。-->
<javaTypeResolver>
<property name="forceBigDecimals" value="true"/>
</javaTypeResolver>
<!--生成对应的pojo所在包-->
<javaModelGenerator targetPackage="cn.bookstore.pojo" targetProject="src/main/java"/>
<!--生成对应mapper所在目录 配置文件-->
<sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources"/>
<!--配置mapper对应的java映射-->
<javaClientGenerator targetPackage="cn.bookstore.mapper" targetProject="src/main/java" type="XMLMAPPER"/>
<!--对应的表-->
<table tableName="notice" enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false" />
<table tableName="orderitem" enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false" />
<table tableName="orders" enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false" />
<table tableName="products" enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false" />
<table tableName="user" enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false" />
</context>
</generatorConfiguration>
运行即可自动生成
当mysql中的字段为text类型,非java中常见类型,会导致 Example类中缺少该字段的判断语句,导致最后查询的时候,不会查询到该字段的值。