当前位置: 首页 > news >正文

mybatis-generator插件自动生成mapper及其实体模型配置

先赞后看,养成习惯!!! ^ _ ^ ❤️ ❤️ ❤️
码字不易,大家的支持就是我坚持下去的动力,点赞后不要忘记关注我哦

📕本系列文章为本人在学习路上遇到的问题和解决方法,在这里撰写成文是为了巩固知识和帮助其他友友
个人主页:伯明翰java
如有错误,请您指正批评 ^ _ ^

目录结构

目录结构:创建如下文件夹及配置文件(springBoot)。内容见下
在这里插入图片描述

pom文件中引入依赖

在properties标签中加⼊版本号:

<mybatis-generator-plugin-version>1.4.1</mybatis-generator-plugin-version>

在build–>plugins标签中加⼊如下配置:

<!-- mybatis ⽣成器插件 --> 
<plugin><groupId>org.mybatis.generator</groupId><artifactId>mybatis-generator-maven-plugin</artifactId><version>${mybatis-generator-plugin-version}</version><executions><execution><id>Generate MyBatis Artifacts</id><phase>deploy</phase><goals><goal>generate</goal></goals></execution></executions><!-- 相关配置 --> <configuration><!-- 打开⽇志 --> <verbose>true</verbose><!-- 允许覆盖 --> <overwrite>true</overwrite><!-- 配置⽂件路径 --> <configurationFile>src/main/resources/mybatis/generatorConfig.xml</configurationFile></configuration>
</plugin>

创建generatorConfig.xml

在src/main/resources下创建mybatis⽬录,在mybatis⽬录下创建generatorConfig.xml⽂
件,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfigurationPUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN""http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration><!-- 驱动包路径,location中路径替换成⾃⼰本地路径 --> <classPathEntry location="D:\database\jar\mysql-connector-java5.1.49.jar"/><context id="DB2Tables" targetRuntime="MyBatis3"><!-- 禁⽤⾃动⽣成的注释 --> <commentGenerator><property name="suppressAllComments" value="true"/><property name="suppressDate" value="true"/></commentGenerator><!-- 连接配置 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver"connectionURL="jdbc:mysql://127.0.0.1:3306/forum_db?
characterEncoding=utf8&amp;useSSL=false"userId="root"password="123456"></jdbcConnection><javaTypeResolver><!-- ⼩数统⼀转为BigDecimal --> <property name="forceBigDecimals" value="false"/></javaTypeResolver><!-- 实体类⽣成位置 --> <javaModelGenerator targetPackage="com.bitejiuyeke.forum.model" 
targetProject="src/main/java"><property name="enableSubPackages" value="true"/><property name="trimStrings" value="true"/></javaModelGenerator><!-- mapper.xml⽣成位置 --> <sqlMapGenerator targetPackage="mapper" 
targetProject="src/main/resources"><property name="enableSubPackages" value="true"/></sqlMapGenerator><!-- DAO类⽣成位置 --> <javaClientGenerator type="XMLMAPPER" 
targetPackage="com.bitejiuyeke.forum.dao" targetProject="src/main/java"><property name="enableSubPackages" value="true"/></javaClientGenerator><!-- 配置⽣成表与实例, 只需要修改表名tableName, 与对应类名domainObjectName 即
可--> <table tableName="t_article" domainObjectName="Article" 
enableSelectByExample="false"enableDeleteByExample="false" enableDeleteByPrimaryKey="false" 
enableCountByExample="false"enableUpdateByExample="false"><!-- 类的属性⽤数据库中的真实字段名做为属性名, 不指定这个属性会⾃动转换 _ 为
驼峰命名规则--> <property name="useActualColumnNames" value="true"/></table><table tableName="t_article_reply" domainObjectName="ArticleReply" 
enableSelectByExample="false"enableDeleteByExample="false" enableDeleteByPrimaryKey="false" 
enableCountByExample="false"enableUpdateByExample="false"><property name="useActualColumnNames" value="true"/></table><table tableName="t_board" domainObjectName="Board" 
enableSelectByExample="false" enableDeleteByExample="false"enableDeleteByPrimaryKey="false" enableCountByExample="false" 
enableUpdateByExample="false"><property name="useActualColumnNames" value="true"/></table><table tableName="t_message" domainObjectName="Message" 
enableSelectByExample="false"enableDeleteByExample="false" enableDeleteByPrimaryKey="false" 
enableCountByExample="false"enableUpdateByExample="false"><property name="useActualColumnNames" value="true"/></table><table tableName="t_user" domainObjectName="User" 
enableSelectByExample="false" enableDeleteByExample="false"enableDeleteByPrimaryKey="false" enableCountByExample="false" 
enableUpdateByExample="false"><property name="useActualColumnNames" value="true"/></table></context>
</generatorConfiguration>

运⾏插件⽣成⽂件

在src/main/resources下创建mapper⽬录
点下下图重新加载Maven项⽬,在Plugins节点下出现mybatis-generator,双击运⾏,在对应的⽬录下⽣成相应的类与映射⽂件,如下图所⽰:
在这里插入图片描述
在这里插入图片描述

配置mybatis扫描路径

在这里插入图片描述
application.yml中加⼊mybatis配置
在这里插入图片描述
配置成功后就可以扫描mapper目录下的所有xml文件

http://www.dtcms.com/a/461201.html

相关文章:

  • 计算机毕业设计 基于k-means的校园美食推荐系统 Python 大数据毕业设计 Hadoop毕业设计选题【附源码+文档报告+安装调试】
  • 【代码大模型-后门安全】Backdoors in Neural Models of Source Code
  • javaweb后端优雅处理枚举
  • 帝国cms小程序搞起来简直好用的不行
  • 高效批量调整图像尺寸的方案
  • 单片机供电处3.3V大电容导致程序可进调试但是无法暂停到具体语句
  • Java 实战:为 Word 文档中的文本与段落添加边框
  • 创业网站怎么做网站建设与网页设计...
  • git大文件储存机制是什么-为什么有大文件会出错并且处理大文件非常麻烦-优雅草卓伊凡
  • 机器学习之规则学习(Rule Learning)
  • 【神经网络】从逻辑回归到神经网络
  • 工厂抽烟检测系统 智能化安全管控新方案 加油站吸烟检测技术 吸烟行为智能监测
  • 做外贸怎么看外国网站wordpress配置邮件发送
  • 使用Python对PDF进行拆分与合并
  • 嵌入式软件/硬件工程师面试答案
  • 6.DSP学习记录之定时器
  • 阳春新农村建设网站中铁建设集团有限公司西北分公司
  • 简化OffSec考试报告编写:OSCP-Exam-Report-Template-Markdown项目详解
  • 北京网站设计制作过程数据服务网站开发
  • Go基础:一文掌握Go语言网络编程
  • TENGJUN-3.5MM耳机插座(JA06-BPF032-A):反向沉板结构下的4极音频连接解决方案
  • 使用IOT-Tree接入各种设备转OPC UA Server输出
  • 【大模型实战篇】从Python函数到MCP服务器:完整转换示例
  • 怎样增加网站的权重小企业做网站有用吗
  • 【ArkTS-通用事件】
  • 为什么要放弃用Docker?
  • 东方仙盟修仙(五)赛博科技修仙养老是一种爱好
  • 大模型训练过程中主动学习和课程学习的全面对比
  • Redis数据库隔离业务缓存对查询性能的影响分析
  • Mapper接口的解析