一、首先,安装eclipse插件
Help--Eclipser Marketplace中查找:Mybatis Generator 1.3.5安装
二、新建project
New--other--查找如下
点击next,选择你要将文件生成到哪里的项目名
点击finish关闭。就会在hhh项目中生成文件generatorConfig.xml。
注意:hhh项目中要有数据库相关jar包及要生成的包 mapper/pojo,因为一会要在配置文件中进行配置。
三、配置generatorConfig.xml
四、自动生成mapper.java和mapper.xml等文件
右键generatorConfig.xml,选择如下:
之后,就可以在包下看到生成的文件了
End!
<?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>
<!-- classPathEntry:数据库的JDBC驱动的jar包地址 -->
<classPathEntry
location="D:\repository\mysql\mysql-connector-java\5.1.30\mysql-connector-java-5.1.30.jar" />
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 抑制警告 -->
<property name="suppressTypeWarnings" value="true" />
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
<!-- 是否生成注释代时间戳 -->
<property name="suppressDate" value="true" />
</commentGenerator>
<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://172.22.11.158:3306/freeway" userId="root"
password="qBDRae$9Bc2">
</jdbcConnection>
<javaModelGenerator targetPackage="com.ls.freeway.equipmentInfo.dao"
targetProject="freeway-service/src/main/java">
<property name="enableSubPackages" value="false" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="com.ls.freeway.equipmentInfo.dao"
targetProject="freeway-service/src/main/java">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.ls.freeway.equipmentInfo.dao" targetProject="freeway-service/src/main/java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!--生成对应表及类名 -->
<table schema="general" tableName="BH_PBMD_DEV_RUN" domainObjectName="BH_PBMD_DEV_RUN" enableCountByExample="true" enableUpdateByExample="true"
enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true">
<!--domain字段的命名规则,false:默认为驼峰命名 true:按数据库真实命名 -->
<!--<property name="useActualColumnNames" value="false" /> -->
<!-- 忽略列,不生成bean 字段 -->
<!-- <ignoreColumn column="FRED" /> -->
<!-- 指定列的java数据类型 -->
<!-- <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" /> -->
</table>
</context>
</generatorConfiguration>