日常使用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 配置文件

  1. <!--数据库URL,用户名、密码 -->
  2. <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/test?useUnicode=true" userId="root" password="root" />
  1. <!--实体类存储的路径:C:\Users\my\Desktop\mybatis-generator-core-1.3.6\lib\java -->
  2. <javaModelGenerator targetPackage="javaModelGenerator"
  3. targetProject="C:\Users\my\Desktop\mybatis-generator-core-1.3.6\lib\java">
  4. <property name="enableSubPackages" value="true" />
  5. <property name="trimStrings" value="true" />
  6. </javaModelGenerator>
  7. <!--Mapper类存储的路径:C:\Users\my\Desktop\mybatis-generator-core-1.3.6\lib\java-->
  8. <sqlMapGenerator targetPackage="sqlMapGenerator"
  9. targetProject="C:\Users\my\Desktop\mybatis-generator-core-1.3.6\lib\java">
  10. <property name="enableSubPackages" value="false" />
  11. </sqlMapGenerator>
  12. <!--Mapper插入时判断字段非空类存储的路径:C:\Users\my\Desktop\mybatis-generator-core-1.3.6\lib\java-->
  13. <javaClientGenerator type="ANNOTATEDMAPPER" targetPackage="javaClientGenerator"
  14. targetProject="C:\Users\my\Desktop\mybatis-generator-core-1.3.6\lib\java">
  15. <property name="enableSubPackages" value="true" />
  16. </javaClientGenerator>
  1. <!--可一次指定多个表,这里指定了 6 个表-->
  2. <!-- 指定生成的表: tableName是数据库中的表名 domainObjectName是要生成的实体类名-->
  3. <!-- mybatis generator代码生成器在默认的情况下会生成对于表实体类的一个Examle类,可以更改生成器的配置为false避免生成Examle类 -->
  4. <!-- columnOverride:如果不存在则默认按数据库中字段类型创建实体类,如果存在则按以下指定的名称和类型创建实体类字段, -->
  5. <!-- ignoreColumn:在实体类中不创建此属性 -->
  6. <table tableName="wf_admin_action_logs" domainObjectName="AdminActionLogs" enableCountByExample="false" enableUpdateByExample="false"
  7. enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
  8. </table>
  9. <table tableName="wf_admin_menus" domainObjectName="AdminMenus" enableCountByExample="false" enableUpdateByExample="false"
  10. enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
  11. </table>
  12. <table tableName="wf_admin_roles" domainObjectName="AdminRoles" enableCountByExample="false" enableUpdateByExample="false"
  13. enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
  14. </table>
  15. <table tableName="wf_admin_roles_menus" domainObjectName="AdminRolesMenus" enableCountByExample="false" enableUpdateByExample="false"
  16. enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
  17. </table>
  18. <table tableName="wf_admin_users" domainObjectName="AdminUsers" enableCountByExample="false" enableUpdateByExample="false"
  19. enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
  20. </table>
  21. <table tableName="wf_admin_users_roles" domainObjectName="AdminUsersRoles" enableCountByExample="false" enableUpdateByExample="false"
  22. enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
  23. </table>

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



5、运行创建命令

  1. //返回 MyBatis Generator finished successfully. 说明创建成功
  2. 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. 爬虫框架webmagic与spring boot的结合使用--转

    原文地址:http://www.jianshu.com/p/c3fc3129407d 1. 爬虫框架webmagic WebMagic是一个简单灵活的爬虫框架.基于WebMagic,你可以快速开发出一 ...

  2. 用ksh运行一个helloworld

    本文目的在于记录和回顾.不建议当教程. Linux上没有ksh的话yum install ksh就可以了 直接上图 vim一个文件后缀名是ksh 内容是和shell差不多 然后赋予这个文件可执行权限 ...

  3. QT笔记 -- (2) 文件相关操作、中文路径乱码

    1.显示文件对话框,选择一个目录,显示选中目录中的所有图片的代码如下 主要class: QFileDialog QStringList QFileInfoList QDir void open(){ ...

  4. 手把手教你如何新建scrapy爬虫框架的第一个项目(上)

    前几天给大家分享了如何在Windows下创建网络爬虫虚拟环境及如何安装Scrapy,还有Scrapy安装过程中常见的问题总结及其对应的解决方法,感兴趣的小伙伴可以戳链接进去查看.关于Scrapy的介绍 ...

  5. Vue-cli 3.0 构建项目

    Vue-cli是vue的一个脚手架,我们可以通过它来构建我们的前端项目 vue-cli3环境配置 //1. 安装nodeJS(已经集成npm) 首先需要安装node环境,可以直接到中文官网http:/ ...

  6. wordpress 后台登录增加访问效验

    目前已知的增加 wordpress 后台登录安全的方案有三种: 安全插件:如Limit Login Attempts Reloaded.WPS Hide Login 等等: 登录 URL 增加自定义k ...

  7. 解决new Date的值为Invalid Date、NaN-NaN的问题

    错误代码: let timespan = 1515239514230; let dateTime = new Date(timespan); console.log(dateTime) // 返回 I ...

  8. ubuntu 装tensorflow出现 conda install ERROR missing write permission错误

    通过搜索tensorflow然后运行,例如:$ conda install --channel https://conda.anaconda.org/jjh_cio_testing tensorflo ...

  9. Mac安装软件时,提示文件已损坏,需要移动到废纸篓的解决方法

    1.修改系统偏好设置,安全性与隐私-->将“允许从以下位置下载的应用” ☑️任何来源. 2. mac10.12以上的系统一般没有“任何来源”这个选项,需打开terminnal终端,输入 sudo ...

  10. COGS——T 1578. 次小生成树初级练习题

    http://www.cogs.pro/cogs/problem/problem.php?pid=1578 ☆   输入文件:mst2.in   输出文件:mst2.out   简单对比时间限制:1 ...