2. 导入插件
<plugin>??
????<groupId>org.mybatis.generator</groupId>??
????<artifactId>mybatis-generator-maven-plugin</artifactId>??
????<version>1.3.5</version>??
????<dependencies>??
????????<dependency>??
????????????<groupId>org.mybatis.generator</groupId>??
????????????<artifactId>mybatis-generator-core</artifactId>??
????????????<version>1.3.5</version>??
????????</dependency>??
????????<dependency>??
????????????<groupId>mysql</groupId>??
????????????<artifactId>mysql-connector-java</artifactId>??
????????????<version>5.1.41</version>??
????????</dependency>??
????</dependencies>??
????<executions>??
????????<execution>??
????????????<id>mybatis?generator</id>??
????????????<phase>package</phase>??
????????????<goals>??
????????????????<goal>generate</goal>??
????????????</goals>??
????????</execution>??
????</executions>??
????<configuration>??
????????<!--?允许移动生成的文件?-->??
????????<verbose>false</verbose>??
????????<!--?允许自动覆盖文件?-->??
????????<overwrite>false</overwrite>??
????????<configurationFile>??
????????????src/main/resources/mybatis-generator.xml??
????????</configurationFile>??
????</configuration>??
</plugin>??
3. 创建对应包, 在resources文件下创建mybatis-generator.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>??
??
?
????<context?id="default"?targetRuntime="MyBatis3">??
??
?
????????<!--?optional,旨在创建class时,对注释进行控制?-->??
????????<commentGenerator>??
????????????<property?name="suppressDate"?value="true"/>??
????????????<property?name="suppressAllComments"?value="true"/>??
????????</commentGenerator>??
??
?
????????<!--jdbc的数据库连接?-->??
????????<jdbcConnection?driverClass="com.mysql.jdbc.Driver"??
????????????????????????connectionURL="jdbc:mysql://127.0.0.1:3306/xunwu"??
????????????????????????userId="root"??
????????????????????????password="123456">??
????????</jdbcConnection>??
??
?
??
?
????????<!--?非必需,类型处理器,在数据库类型和java类型之间的转换控制-->??
????????<javaTypeResolver>??
????????????<property?name="forceBigDecimals"?value="false"/>??
????????</javaTypeResolver>??
??
?
????????<!--?生成DataObject类存放位置?-->??
????????<javaModelGenerator?targetPackage="com.figsprite.xunwu.dataobject"?targetProject="src/main/java">??
????????????<!--?是否允许子包,即targetPackage.schemaName.tableName?-->??
????????????<property?name="enableSubPackages"?value="false"/>??
????????????<!--?是否对DO添加?构造函数?-->??
????????????<property?name="constructorBased"?value="true"/>??
????????????<!--?是否对类CHAR类型的列的数据进行trim操作?-->??
????????????<property?name="trimStrings"?value="true"/>??
????????????<!--?建立的DO对象是否?不可改变??即生成的Model对象不会有?setter方法,只有构造方法?-->??
????????????<property?name="immutable"?value="false"/>??
????????</javaModelGenerator>??
????????<!--?生成映射文件存放位置?-->??
????????<sqlMapGenerator?targetPackage="mapping"?targetProject="src/main/resources">??
????????????<property?name="enableSubPackages"?value="false"/>??
????????</sqlMapGenerator>??
??
?
????????<!--?生成Dao类存放位置?-->??
????????<!--?客户端代码,生成易于使用的针对Model对象和XML配置文件的代码??
??????????????type="ANNOTATIONDMAPPER",生成Java?Model和基于注解的Mapper?对象??
??????????????type="MIXEDMAPPER",生成基于注解的Java?Model和相应的Mapper对象??
??????????????type="XMLMAPPER",生成SQLMap?XML?文件和独立的Mapper接口-->??
????????<javaClientGenerator?type="XMLMAPPER"?targetPackage="com.figsprite.xunwu.dao"?targetProject="src/main/java">??
????????????<property?name="enableSubPackages"?value="true"/>??
????????</javaClientGenerator>??
??
?
??
?
????????<table?tableName="house"?domainObjectName="House"?enableCountByExample="false"?enableUpdateByExample="false"?enableDeleteByExample="false"?enableSelectByExample="false"?selectByExampleQueryId="false"></table>??
????????<table?tableName="house_detail"?domainObjectName="HouseDetail"?enableCountByExample="false"?enableUpdateByExample="false"?enableDeleteByExample="false"?enableSelectByExample="false"?selectByExampleQueryId="false"></table>??
????????<table?tableName="house_picture"?domainObjectName="HousePicture"?enableCountByExample="false"?enableUpdateByExample="false"?enableDeleteByExample="false"?enableSelectByExample="false"?selectByExampleQueryId="false"></table>??
????????<table?tableName="house_subscribe"?domainObjectName="HouseSubscribe"?enableCountByExample="false"?enableUpdateByExample="false"?enableDeleteByExample="false"?enableSelectByExample="false"?selectByExampleQueryId="false"></table>??
????????<table?tableName="house_tag"?domainObjectName="HouseTag"?enableCountByExample="false"?enableUpdateByExample="false"?enableDeleteByExample="false"?enableSelectByExample="false"?selectByExampleQueryId="false"></table>??
????????<table?tableName="role"?domainObjectName="Role"?enableCountByExample="false"?enableUpdateByExample="false"?enableDeleteByExample="false"?enableSelectByExample="false"?selectByExampleQueryId="false"></table>??
????????<table?tableName="subway"?domainObjectName="Subway"?enableCountByExample="false"?enableUpdateByExample="false"?enableDeleteByExample="false"?enableSelectByExample="false"?selectByExampleQueryId="false"></table>??
????????<table?tableName="subway_station"?domainObjectName="SubwayStation"?enableCountByExample="false"?enableUpdateByExample="false"?enableDeleteByExample="false"?enableSelectByExample="false"?selectByExampleQueryId="false"></table>??
????????<table?tableName="support_address"?domainObjectName="SupportAddress"?enableCountByExample="false"?enableUpdateByExample="false"?enableDeleteByExample="false"?enableSelectByExample="false"?selectByExampleQueryId="false"></table>??
????????<table?tableName="user"?domainObjectName="User"?enableCountByExample="false"?enableUpdateByExample="false"?enableDeleteByExample="false"?enableSelectByExample="false"?selectByExampleQueryId="false"></table>??
??
?
????</context>??
</generatorConfiguration>??
4. 加上生成命令
5. Run