第一步:在resources文件夹下创建一个目录mybatis-generator,在目录mybatis-generator下创建文件generatorConfig.xml(此处的目录名可任意取)

第二步:在pom文件标签<plugins>处引入依赖

<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.5</version>
<configuration>
<configurationFile>${basedir}/src/main/resources/mybatis-generator/generatorConfig.xml
</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
</plugin>

第三步:配置generatorConfig.xml

注:①标红处即为需要修改处

②"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" 在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>
<!-- 连接数据库jar包的路径-->
<classPathEntry location="/Users/dxm1/.m2/repository/mysql/mysql-connector-java/5.1.48/mysql-connector-java-5.1.48.jar"/>
<context id="DB2Tables" 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://localhost:3306/test_db?serverTimezone=UTC&amp;useSSL=false"
userId="root"
password="zu273334ly">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver> <!-- 实体类的包名和存放路径 -->
<javaModelGenerator targetPackage="com.example.demo.model" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator> <!-- 生成映射文件*.xml的位置-->
<sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator> <!-- 生成DAO的包名和位置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.example.demo.dao" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator> <!-- tableName:数据库中的表名或视图名;domainObjectName:生成的实体类的类名-->
<table tableName="GENERAL_BALANCE_PLAN" domainObjectName="GeneralBalancePlan"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false"/>
<!--
<table tableName="xxx" domainObjectName="xxx"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false"/>
...
<table tableName="xxx" domainObjectName="xxx"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false"/>
-->
</context>
</generatorConfiguration>

如何找连接数据库jar包的路径,可参考 https://blog.csdn.net/weixin_43228497/article/details/83114594

第四步:启动

参考资料: https://blog.csdn.net/weixin_42250302/article/details/106986707

MyBatis Generator使用方法的更多相关文章

  1. mybatis generator 使用方法

    环境: ubuntu   eclipse maven 一. 简介 mybatis-geneator是一款mybatis自动代码生成工具,可以通过配置,快速生成mapper和xml文件以及pojo 二. ...

  2. Mybatis Generator自动生成的mapper只有insert方法

    – Mybatis Generator 生成的mapper只有insert方法 – 首先检查generatorConfig.xml中table项中的属性 enableSelectByPrimaryKe ...

  3. Mybatis Generator的model生成中文注释,支持oracle和mysql(通过实现CommentGenerator接口的方法来实现)

    自己手动实现的前提,对maven项目有基本的了解,在本地成功搭建了maven环境,可以参考我之前的文章:maven环境搭建 项目里新建表时model,mapper以及mapper.xml基本都是用My ...

  4. mybatis generator自动生成sqlmap代码的不完善之处以及解决方法

    a) 建表时,字段名称建议用"_"分隔多个单词,比如:AWB_NO.REC_ID...,这样生成的entity,属性名称就会变成漂亮的驼峰命名,即:awbNo.recId b)or ...

  5. Mybatis—三剑客之generator使用方法

    三剑客之generator主要用于自动生成POJO实体类   准备素材: mybatis-generator-core-1.3.2.jar     mysql-connector-java-5.1.2 ...

  6. mybatis Generator生成代码及使用方式

    本文原创,转载请注明:http://www.cnblogs.com/fengzheng/p/5889312.html 为什么要有mybatis mybatis 是一个 Java 的 ORM 框架,OR ...

  7. mybatis generator 自动生成dao层映射代码

    资源: doc url :http://www.mybatis.org/generator/ download:https://github.com/mybatis/generator/release ...

  8. MyBatis Generator作为maven插件自动生成增删改查代码及配置文件例子

    什么是MyBatis Generator MyBatis Generator (MBG) 是一个Mybatis的代码生成器,可以自动生成一些简单的CRUD(插入,查询,更新,删除)操作代码,model ...

  9. Mybatis Generator生成工具配置文件详解

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

  10. MyBatis Generator 详解

    MyBatis Generator中文文档 MyBatis Generator中文文档地址:http://mbg.cndocs.tk/ 该中文文档由于尽可能和原文内容一致,所以有些地方如果不熟悉,看中 ...

随机推荐

  1. docker登录Ubuntu出现error storing credentials - err: exit status 1, out: `Cannot autolaunch D-Bus without X11 $DISPLAY`的解决方法

    命令行登录docker时,在Ubuntu 18.04下可能会出现 error storing credentials - err: exit status 1, out: `Cannot autola ...

  2. 基于Nginx上的docker负载均衡

    1.首先需要拖拽镜像文件   docker  pull nginx 2.生成多个docker容器 docker run --name demo1 -d -p 8081:80 -v /data/demo ...

  3. gitee上传VS2022已有项目

    1.在gitee上新建仓库: 2.复制新建仓库地址: 3.用VS2022打开先有项目,找到Git更改项: 4.点击创建Git存储库: 5.创建本地仓库并推送到远程,点击创建并推送: 6.等待创建成功即 ...

  4. Linux: Ensure X Window System is not installed

    参考 2.2.2 Ensure X Window System is not installed X window System是什么 The X Window System provides a G ...

  5. 百题计划-4 codeforces 652 div2 D. TediousLee 找规律

    https://codeforces.com/contest/1369/problem/D n<=2e6,所以只要找递推式就可以了,不需要找快速幂 /** */ #include<bits ...

  6. linux清除恶意程序流程-kdevtmpfsi清除

    TOP命令查看发现kdevtmpfsi进程跑满CPU, 处理如下: 解决过程 1.清除被新增的用户名和密码# 找到账户ID和权限组都是0跟root同级别的和不认识的, 删掉保存.   more /va ...

  7. centos7升级内核 ,wireguard优化

    一.centos7升级内核 uname -r 查看内核版本 升级前 升级后 参考链接: https://www.cnblogs.com/rick-zhang/p/14944510.html # 启用 ...

  8. python语法中的左值、右值和字符

    位置决定语义 在下面的python代码中,忽略掉语法错误,源码中同样一个单词tsecer在不同的位置有不同的意义 import之后 在import之后的tsecer是作为一个简单的字面字符串来处理:这 ...

  9. .net ef 链接 mysql

    https://blog.csdn.net/weixin_30394975/article/details/114168133

  10. 安装gitlab的总结

    安装过程参考文档 http://www.linuxe.cn/post-520.html https://www.bilibili.com/read/cv4602641 备注要点: 1.gitlab安装 ...