日常使用Mybatis少不了和实体类和 Mapper 打交道。除了我们手写来实现,还可以使用 mybatis-generator-core 来快速生成 实体类和 Mapper。

步骤如下:

1、下载 mybatis-generator-core 到本地

下载链接:https://pan.baidu.com/s/1wTZ_7RTwToaW8oYm81WkLw 密码:lr6x

2、使用 IDEA 打开 mybatis-generator-core

3、配置 generatorConfig.xml 配置文件

<!--数据库URL,用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/test?useUnicode=true" userId="root" password="root" />
<!--实体类存储的路径:C:\Users\my\Desktop\mybatis-generator-core-1.3.6\lib\java -->
  <javaModelGenerator targetPackage="javaModelGenerator"
                       targetProject="C:\Users\my\Desktop\mybatis-generator-core-1.3.6\lib\java">
      <property name="enableSubPackages" value="true" />
      <property name="trimStrings" value="true" />
  </javaModelGenerator>

<!--Mapper类存储的路径:C:\Users\my\Desktop\mybatis-generator-core-1.3.6\lib\java-->
  <sqlMapGenerator targetPackage="sqlMapGenerator"
                   targetProject="C:\Users\my\Desktop\mybatis-generator-core-1.3.6\lib\java">
       <property name="enableSubPackages" value="false" />
  </sqlMapGenerator>

<!--Mapper插入时判断字段非空类存储的路径:C:\Users\my\Desktop\mybatis-generator-core-1.3.6\lib\java-->
  <javaClientGenerator type="ANNOTATEDMAPPER" targetPackage="javaClientGenerator"
                        targetProject="C:\Users\my\Desktop\mybatis-generator-core-1.3.6\lib\java">
    <property name="enableSubPackages" value="true" />
  </javaClientGenerator>
        <!--可一次指定多个表,这里指定了 6 个表-->
        <!-- 指定生成的表: tableName是数据库中的表名 domainObjectName是要生成的实体类名-->
        <!-- mybatis generator代码生成器在默认的情况下会生成对于表实体类的一个Examle类,可以更改生成器的配置为false避免生成Examle类 -->
        <!-- columnOverride:如果不存在则默认按数据库中字段类型创建实体类,如果存在则按以下指定的名称和类型创建实体类字段, -->
        <!-- ignoreColumn:在实体类中不创建此属性 -->
        <table tableName="wf_admin_action_logs" domainObjectName="AdminActionLogs" enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
        </table>

        <table tableName="wf_admin_menus" domainObjectName="AdminMenus" enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
        </table>

        <table tableName="wf_admin_roles" domainObjectName="AdminRoles" enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
        </table>

        <table tableName="wf_admin_roles_menus" domainObjectName="AdminRolesMenus" enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
        </table>

        <table tableName="wf_admin_users" domainObjectName="AdminUsers" enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
        </table>

        <table tableName="wf_admin_users_roles" domainObjectName="AdminUsersRoles" enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
        </table>

4、IDEA打开命令行窗口或Windows+r打开命令行窗口



5、运行创建命令

//返回 MyBatis Generator finished successfully. 说明创建成功
java -jar mybatis-generator-core-1.3.6.jar -configfile generatorConfig.xml -overwrite

thanks~

mybatis-generator-core快速生成实体类和Mapper的更多相关文章

  1. 使用eclipse插件mybatis generator来自动生成实体类及映射文件

    <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE generatorConfiguratio ...

  2. Springboot mybatis generate 自动生成实体类和Mapper

    https://github.com/JasmineQian/SpringDemo_2019/tree/master/mybatis Springboot让java开发变得方便,Springboot中 ...

  3. mybatis根据表逆向自动化生成代码(自动生成实体类、mapper文件、mapper.xml文件)

    .personSunflowerP { background: rgba(51, 153, 0, 0.66); border-bottom: 1px solid rgba(0, 102, 0, 1); ...

  4. idea快速生成实体类

    1.打开idea的视图,选择Database 2.选择对应的数据库[这里是mysql为例] 3.输入自己对应的内容,输入完成可点击Test Connection进行测试,成功SUCCESS 4.点击确 ...

  5. 第二篇 Springboot mybatis generate根据数据库表自动生成实体类、Mapper和Mapper.xml

    源码链接:https://pan.baidu.com/s/1iP4UguBufHbcIEv4Ux4wDw 提取码:j6z9 目录结构如下:只需增加一个generatorConfig.xml文件和在po ...

  6. 使用generatorConfig配置,自动生成实体类,Mapper接口等

    1.在项目的resource目录下面配置generatorConfig.properties文件,以及generatorConfig.xml文件 generatorConfig.properties文 ...

  7. 使用maven的mybatis-generator代码生成器插件生成实体类、mapper配置文件和mapper接口(使用idea)

    接着之前创建的ssmMaven项目 一: 在pom文件中加入mybatis-generator插件 <plugins> <plugin> <groupId>org. ...

  8. idea快速生成实体类Entity

    1)打开idea 2)添加mysql的数据连接 3)生成类

  9. Mybatis自动生成实体类、dao接口和mapping映射文件

    由于Mybatis是一种半自动的ORM框架,它的工作主要是配置mapping映射文件,为了减少手动书写映射文件,可以利用mybatis生成器,自动生成实体类.dao接口以及它的映射文件,然后直接拷贝到 ...

随机推荐

  1. 07:清泉-改(prime+堆)

    时间限制:  10000ms 单个测试点时间限制:  1000ms 内存限制:  512000kB 描述 华北电力大学可以抽象为一张有n个点m条边的无向图. 现在所有的边都断了. 修复每条边都有个不同 ...

  2. JavaScript 中表达式和语句的区别

    1.语句和表达式 JavaScript中的表达式和语句是有区别的.一个表达式会产生一个值,它可以放在任何需要一个值的地方,比如,作为一个函数调用的参数.下面的每行代码都是一个表达式: myvar3 + ...

  3. 解决js计算 小数加减乘除失真的功能函数

    function floatPoint(one,two,str){ //转化为字符串 one = ''+one two = ''+two //切割成整数部分和小数部分 var oneStr = one ...

  4. Linux创建用户和随机密码

    #!/bin/bash#批量创建10个系统帐号并设置密码rm -f user.logfor name in `seq 10`do #非交互式的输入随机密码 password=`echo $RANDOM ...

  5. 学习《PythonWeb开发实战(董伟明)》中文PDF+源代码

    python可以用了进行数据分析,也可以进行Web开发,一般会使用django或者flask等进行开发. 国内介绍python web的书有写的不错的,推荐看看<PythonWeb开发实战> ...

  6. Android自己定义处理崩溃异常

    用过安卓手机的用户以及安卓开发人员们会时长碰到程序异常退出的情况.普通用户遇到这样的情况,肯定非常恼火,甚至会骂一生垃圾软件,然后卸载掉.那么开发人员们在开发过程中遇到这样的情况给怎么办呢,当然,你不 ...

  7. drupal7 怎样将一个date字段加入上日期插件效果

    //这里以created字段为样例 function Hook_form_alter($form,$form_state,$form_id){ $form['created']['#type'] = ...

  8. STL_算法_Heap算法(堆排)(精)

    C++ Primer 学习中. . . 简单记录下我的学习过程 (代码为主) /***************************************** STL-算法--Heap算法 堆排序 ...

  9. 实现浮点数的四舍五入RoundOff,保留几位小数

    直接上代码,非常简短 double myRound(double d,int n) { d = d*pow(10,n); d += 0.5; d = (long)d; d = d/pow(10,n); ...

  10. ORA-06553:PLS-306:wrong number or types of arguments in call to &#39;&#39;

    1.错误描写叙述 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/ ...