<!--导入依赖和插件-->
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.5</version>
</dependency>
<!--mybatis产生助手-->
<dependency>
<groupId>com.ithiema</groupId>
<artifactId>mybatis-generator</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
</configuration>
</plugin>
</plugins>
</build>
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>
<!--加载配置文件,为下面读取数据库信息准备-->
<!--提供jdbc的驱动,因为generator插件在工作时会访问mysql数据库,因此要指定jdbc驱动的位置-->
<classPathEntry
location="d:\mysql-connector-java-5.1.5.jar" />
<!-- 一个数据库一个context -->
<context id="Mysql" targetRuntime="MyBatis3" >
<!-- 注释 -->
<commentGenerator>
<property name="suppressAllComments" value="true"/><!-- 是否取消注释 -->
<property name="suppressDate" value="true"/> <!-- 是否生成注释代时间戳-->
</commentGenerator>
<!--数据库链接地址账号密码,这里是读取application.properties配置文件的。
如果你的项目配置文件用的是yml格式的,则如下写法是读取不到,需手动填写完整
-->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/health?useUnicode=true&characterEncoding=utf-8"
userId="root"
password="root">
</jdbcConnection>
<!-- 类型转换 -->
<javaTypeResolver>
<!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) -->
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!--生成pojo类存放位置-->
<javaModelGenerator targetPackage="com.xx.pojo" targetProject="src\main\java">
<property name="enableSubPackages" value="false"></property>
<property name="trimStrings" value="true"></property>
</javaModelGenerator>
<!-- 生成mapper.xml文件,dao.xml存放路径 -->
<sqlMapGenerator targetPackage="com.xx.dao" targetProject="src/main/resources">
<property name="enableSubPackages" value="false"/>
</sqlMapGenerator>
<!-- 生成mapper.xml对应得接口,也就是dao层 -->
<javaClientGenerator targetPackage="com.xx.dao" targetProject="src/main/java" type="XMLMAPPER">
<property name="enableSubPackages" value="false"/>
</javaClientGenerator>
<!--以下就是需自动生成mapper.xml文件等表,配置哪些表,就自动生成哪些表那些文件。-->
<table tableName="t_checkitem" domainObjectName="CheckItem" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
<generatedKey column="id" sqlStatement="Mysql" identity="true" />
</table>
<table tableName="t_checkgroup" domainObjectName="CheckGroup" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
<generatedKey column="id" sqlStatement="Mysql" identity="true" />
</table>
<table tableName="t_setmeal" domainObjectName="Setmeal" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
<generatedKey column="id" sqlStatement="Mysql" identity="true" />
</table>
</context>
</generatorConfiguration>