MyBatis-Generator在Eclipse下插件安装及使用

1.打开Eclipse-Help-Eclipse Marketplace,在【find】中输入“MyBatis-Generator”可以看到下图

MyBatis-Generator在Eclipse下插件安装及使用

2.安装提示步骤进行安装

3.编写生成数据model、mapper、mapper 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>

  <!--配置数据库驱动的绝对目录-->

  <classPathEntry location="/Users/nanxiaotao/.m2/repository/mysql/mysql-connector-java/5.1.40/mysql-connector-java-5.1.40.jar" />


  <context id="mysql" targetRuntime="MyBatis3">

    <!--配置数据库驱动类、链接url、用户名、密码-->

    <jdbcConnection driverClass="com.mysql.jdbc.Driver"

                        connectionURL="jdbc:mysql://127.0.0.1:3306/microservicedb1" userId="root"

                        password="******">

    </jdbcConnection>


    <javaTypeResolver >

      <property name="forceBigDecimals" value="false" />

    </javaTypeResolver>

    <!--配置生成model类的包目录-->

    <javaModelGenerator targetPackage="com.pku.springboot.model" targetProject="springboot">

      <property name="enableSubPackages" value="true" />

      <property name="trimStrings" value="true" />

    </javaModelGenerator>

    <!--配置生成mapper接口的包目录-->

    <sqlMapGenerator targetPackage="com.pku.springboot.mapper"  targetProject="springboot">

      <property name="enableSubPackages" value="true" />

    </sqlMapGenerator>

    <!--配置生成mapper映射xml文件的包目录-->

    <javaClientGenerator type="XMLMAPPER" targetPackage="com.pku.springboot.mapper"  targetProject="springboot">

      <property name="enableSubPackages" value="true" />

    </javaClientGenerator>


    <!--配置库表生成信息-->

    <table tableName="t_user" domainObjectName="UserInfo"

               enableCountByExample="false" enableUpdateByExample="false"

               enableDeleteByExample="false" enableSelectByExample="false"

               selectByExampleQueryId="false">

    </table>


  </context>

</generatorConfiguration>

4.执行

选中步骤3编写好的配置文件【右键点击】-Run As-Run MyBatis Generator即可