mybatis-generator-xxxx 使用方法

mybatis-generator 下载

自动生成mapper.xml.mapper.java,javabean

官网下载:http://blog.mybatis.org/

下载完成后目录

进入到lib目录下,加入mysql驱动jar包,创建src文件夹,创建generatorConfig.xml文件

在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>

  <!--MySQL连接驱动-->
  <classPathEntry location="mysql-connector-java-5.1.9.jar" />
  
  <!--数据库链接URL,用户名、密码 -->
  <context id="MySQL" targetRuntime="MyBatis3">
    <commentGenerator>  
            <property name="suppressDate" value="true"/>  
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->  
            <property name="suppressAllComments" value="true"/>  
    </commentGenerator> 
    <jdbcConnection driverClass="com.mysql.jdbc.Driver"
        connectionURL="jdbc:mysql://127.0.0.1/hrs"
        userId="root"
        password="123456">
    </jdbcConnection>

    <!--是否启用java.math.BigDecimal-->
    <javaTypeResolver >
      <property name="forceBigDecimals" value="false" />
    </javaTypeResolver>
<!--生成po的包名和位置-->
    <javaModelGenerator targetPackage="cn.behle.hrs.po" targetProject="src">
      <property name="enableSubPackages" value="true" />
      <property name="trimStrings" value="true" />
    </javaModelGenerator>
<!--生成映射文件的包名和位置-->
    <sqlMapGenerator targetPackage="cn.behle.hrs.mapper"  targetProject="src">
      <property name="enableSubPackages" value="true" />
    </sqlMapGenerator>
<!--生成DAO的包名和位置-->
    <javaClientGenerator type="XMLMAPPER" targetPackage="cn.behle.hrs.mapper"  targetProject="src">
      <property name="enableSubPackages" value="true" />
    </javaClientGenerator>
<!--要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
    <table tableName="user" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
    </table>
    <table tableName="position" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
    </table>
    <table tableName="department" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
    </table>
  </context>
</generatorConfiguration>

  

  然后打开命令行

进去到lib目录下

然后输入

//注意mybatis-generator包版本和xml文件名字
java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite

  

原文地址:https://www.cnblogs.com/durui/p/8279885.html