日常使用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. 17.广度优先遍历bfs

    #include <iostream> #include <boost/config.hpp> //图(矩阵实现) #include <boost/graph/adjac ...

  2. NVMe到底是什么?

    转:http://www.expreview.com/42142.html 有关注SSD的朋友应该今年听到NVMe这个词的频率应该不低,随着高端SSD的战场已经抛弃SATA向PCI-E转移,老旧的AH ...

  3. Linux基础03

    ** Linux基本操作常用命令(三) ** Linux的软件包 Linux的软件把分为“源码包”和“二进制包” 源码包:免费,开源 二进制包:系统默认包,即RPM包(上一节我们通过rpm卸载过ope ...

  4. 51nod 1272 最大距离 O(nlog(n)) , 快排 , 最大连续子串

    题目: 解法:排序,把值小的和索引小的放在前面,记录一下之前索引最小的就可以了. 没什么可以讲的,上代码吧: #include <bits\stdc++.h> using namespac ...

  5. BZOJ2225: [Spoj 2371]Another Longest Increasing CDQ分治,3维LIS

    Code: #include <cstdio> #include <algorithm> #include <cstring> #define maxn 20000 ...

  6. 解决Vue引入百度地图JSSDK:BMap is undefined 问题

    百度地图官网文档介绍使用JSSDK时,仅提供了2种引入方式: script引入 异步加载 解决跨域问题,实例调用百度地图 但vue项目中仅某一两个页面需要用到百度地图,所以不想在 index.html ...

  7. [luogu] P2787 语文1(chin1)- 理理思维(分块)

    P2787 语文1(chin1)- 理理思维 题目背景 蒟蒻HansBug在语文考场上,挠了无数次的头,可脑子里还是一片空白. 题目描述 考试开始了,可是蒟蒻HansBug脑中还是一片空白.哦不!准确 ...

  8. UVA 11248 Frequency Hopping

    Frequency Hopping Time Limit: 10000ms Memory Limit: 131072KB This problem will be judged on UVA. Ori ...

  9. FS,FT,DFT,DFS和DTFT的关系

    对于初学数字信号(Digital Signal Processing,DSP)的人来说,这几种变换是最为头疼的,它们是数字信号处理的理论基础,贯穿整个信号的处理. FS:时域上任意连续的周期信号可以分 ...

  10. hihocoder 1124 : 好矩阵 dp

    好矩阵 时间限制:3000ms 单点时限:1000ms 内存限制:256MB 描写叙述 给定n, m.一个n × m矩阵是好矩阵当且仅当它的每一个位置都是非负整数,且每行每列的和 ≤ 2.求好矩阵的个 ...