一、在pom文件中加入插件
<build>
<finalName>web-ssm</finalName>
<pluginManagement>
<plugins>
<!-- 配置Tomcat插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>80</port>
</configuration>
</plugin>
<!-- MyBatis Generator -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
二、加入配置文件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>
<!--导入属性配置 -->
<properties resource="generator.properties"></properties>
<!--指定特定数据库的jdbc驱动jar包的位置 -->
<classPathEntry location="${jdbc.driverLocation}"/>
<context id="default" targetRuntime="MyBatis3">
<plugin type="org.mybatis.generator.plugins.SerializablePlugin" />
<!-- optional,旨在创建class时,对注释进行控制 -->
<commentGenerator>
<property name="suppressDate" value="true" />
</commentGenerator>
<!--jdbc的数据库连接 -->
<jdbcConnection driverClass="${jdbc.driverClass}" connectionURL="${jdbc.connectionURL}" userId="${jdbc.userId}" password="${jdbc.password}">
</jdbcConnection>
<!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制-->
<javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
targetPackage 指定生成的model生成所在的包名
targetProject 指定在该项目下所在的路径
-->
<javaModelGenerator targetPackage="SSM.model"
targetProject="src\main\java" />
<sqlMapGenerator targetPackage="mapping"
targetProject="src\main\resources" />
<javaClientGenerator targetPackage="SSM.dao"
targetProject="src\main\java" type="XMLMAPPER" />
<!--<table schema="ftplist" tableName="db_ftplist">-->
<!--<!– 实体类中的成员变量和表的列明一一对应 –>-->
<!--<property name="useActualColumnNames" value="true"/>-->
<!--</table>-->
<table tableName="user" domainObjectName="user">
</table>
<table tableName="role" domainObjectName="role">
</table>
<table tableName="resource" domainObjectName="resource">
</table>
<!--<table tableName="lession" schema="louis">-->
<!--<!– optional , only for mybatis3 runtime-->
<!--自动生成的键值(identity,或者序列值)-->
<!--如果指定此元素,MBG将会生成<selectKey>元素,然后将此元素插入到SQL Map的<insert> 元素之中-->
<!--sqlStatement 的语句将会返回新的值-->
<!--如果是一个自增主键的话,你可以使用预定义的语句,或者添加自定义的SQL语句. 预定义的值如下:-->
<!--Cloudscape This will translate to: VALUES IDENTITY_VAL_LOCAL()-->
<!--DB2: VALUES IDENTITY_VAL_LOCAL()-->
<!--DB2_MF: SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1-->
<!--Derby: VALUES IDENTITY_VAL_LOCAL()-->
<!--HSQLDB: CALL IDENTITY()-->
<!--Informix: select dbinfo('sqlca.sqlerrd1') from systables where tabid=1-->
<!--MySql: SELECT LAST_INSERT_ID()-->
<!--SqlServer: SELECT SCOPE_IDENTITY()-->
<!--SYBASE: SELECT @@IDENTITY-->
<!--JDBC: This will configure MBG to generate code for MyBatis3 suport of JDBC standard generated keys. This is a database independent method of obtaining the value from identity columns.-->
<!--identity: 自增主键 If true, then the column is flagged as an identity column and the generated <selectKey> element will be placed after the insert (for an identity column). If false, then the generated <selectKey> will be placed before the insert (typically for a sequence).-->
<!--–>-->
<!--<generatedKey column="" sqlStatement="" identity="" type=""/>-->
<!--<!– optional.-->
<!--列的命名规则:-->
<!--MBG使用 <columnRenamingRule> 元素在计算列名的对应 名称之前,先对列名进行重命名,-->
<!--作用:一般需要对BUSI_CLIENT_NO 前的BUSI_进行过滤-->
<!--支持正在表达式-->
<!--searchString 表示要被换掉的字符串-->
<!--replaceString 则是要换成的字符串,默认情况下为空字符串,可选-->
<!--–>-->
<!--<columnRenamingRule searchString="" replaceString=""/>-->
<!--<!– optional.告诉 MBG 忽略某一列-->
<!--column,需要忽略的列-->
<!--delimitedColumnName:true ,匹配column的值和数据库列的名称 大小写完全匹配,false 忽略大小写匹配-->
<!--是否限定表的列名,即固定表列在Model中的名称-->
<!--–>-->
<!--<ignoreColumn column="PLAN_ID" delimitedColumnName="true" />-->
<!--<!–optional.覆盖MBG对Model 的生成规则-->
<!--column: 数据库的列名-->
<!--javaType: 对应的Java数据类型的完全限定名-->
<!--在必要的时候可以覆盖由JavaTypeResolver计算得到的java数据类型. For some databases, this is necessary to handle "odd" database types (e.g. MySql's unsigned bigint type should be mapped to java.lang.Object).-->
<!--jdbcType:该列的JDBC数据类型(INTEGER, DECIMAL, NUMERIC, VARCHAR, etc.),该列可以覆盖由JavaTypeResolver计算得到的Jdbc类型,对某些数据库而言,对于处理特定的JDBC 驱动癖好 很有必要(e.g. DB2's LONGVARCHAR type should be mapped to VARCHAR for iBATIS).-->
<!--typeHandler:-->
<!--–>-->
<!--<columnOverride column="" javaType="" jdbcType="" typeHandler="" delimitedColumnName="" />-->
<!--</table>-->
</context>
</generatorConfiguration>
三、配置generator.properties文件
配置数据库连接等信息
jdbc.driverLocation=E:\\apache-tomcat-8.5.9\\lib\\mysql-connector-java-5.1.29.jar
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.connectionURL=jdbc:mysql://localhost:3306/myshiro?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
jdbc.userId=tuijie
jdbc.password=tuijie
四、配置Maven启动项
配置:mybatis-generator:generate -e