新闻详情

新闻详情

首页 / 资讯中心 / 详情

【09】SpringBoot4 MyBatisPlus 增删改查(CRUD)

发布时间:2026/9/28 20:45:13来源:尧图网络
【09】SpringBoot4 MyBatisPlus 增删改查(CRUD)
SpringBoot4 MyBatisPlus 增删改查CRUD前言pom.xml 文件更新增删改查CRUD测试类前言在此博文《SpringBoot4 MyBatisPlus 代码自动生成》的基础上进行迭代功能开发。pom.xml 文件更新新增 测试坐标dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactId/dependency增删改查CRUD测试类packagecom.junjiu.mybatisplus.pro.test;importcom.junjiu.mybatisplus.pro.entity.TbClient;importcom.junjiu.mybatisplus.pro.service.ITbClientService;importorg.junit.jupiter.api.Test;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.boot.test.context.SpringBootTest;importjava.time.LocalDateTime;importjava.util.List;/** * 测试增删改查功能 */SpringBootTestpublicclassCrudTest{AutowiredITbClientServiceclientService;/** * 添加数据 */TestpublicvoidtestInsert(){TbClientclientnewTbClient().setClientId(100001L).setUserNo(zhangsan).setUserPassword(123456).setNickName(张三).setRealName(张三).setInfo( { age: 25, gender: male, city: 上海 } ).setCreatedTime(LocalDateTime.now()).setUpatedTime(LocalDateTime.now());clientService.save(client);}/** * 批量添加 */TestpublicvoidtestInsertBatch(){ListTbClientclientsList.of(newTbClient().setClientId(100001L).setUserNo(zhangsan).setUserPassword(123456).setNickName(张三).setRealName(张三).setInfo( { age: 25, gender: male, city: 上海 } ).setCreatedTime(LocalDateTime.now()).setUpatedTime(LocalDateTime.now()),newTbClient().setClientId(100002L).setUserNo(lisi).setUserPassword(123456).setNickName(李四).setRealName(李四).setInfo( { age: 28, gender: male, city: 北京 } ).setCreatedTime(LocalDateTime.now()).setUpatedTime(LocalDateTime.now()),newTbClient().setClientId(100003L).setUserNo(wangwu).setUserPassword(123456).setNickName(王五).setRealName(王五).setInfo( { age: 30, gender: male, city: 深圳 } ).setCreatedTime(LocalDateTime.now()).setUpatedTime(LocalDateTime.now()),newTbClient().setClientId(100004L).setUserNo(xiaohong).setUserPassword(123456).setNickName(小红).setRealName(李红).setInfo( { age: 23, gender: female, city: 杭州 } ).setCreatedTime(LocalDateTime.now()).setUpatedTime(LocalDateTime.now()),newTbClient().setClientId(100005L).setUserNo(ai_user).setUserPassword(123456).setNickName(AI用户).setRealName(陈明).setInfo( { age: 27, gender: male, city: 上海, tags: [Java, Spring Boot, AI], vipLevel: 3 } ).setCreatedTime(LocalDateTime.now()).setUpatedTime(LocalDateTime.now()));clientService.saveBatch(clients);}/** * 修改数据. */TestpublicvoidtestUpdate(){TbClientclientnewTbClient().setClientId(100001L).setUserNo(junjiu).setUserPassword(123456).setNickName(君九DBA).setRealName(君九).setInfo( { age: 25, gender: male, city: 上海 } ).setCreatedTime(LocalDateTime.now()).setUpatedTime(LocalDateTime.now());// clientService.save(client);clientService.updateById(client);}/** * 删除数据. */TestpublicvoidtestDelete(){clientService.removeById(100001L);}}
网站建设高端定制企业官网
RELATED

相关资讯

更多精彩内容,欢迎继续阅读

较早相关资讯

最新相关资讯

AI视觉项目初始化:Windows目录结构与工具链实战指南 2026/9/28 21:28:42

AI视觉项目初始化:Windows目录结构与工具链实战指南

1. 这不是一条命令,而是一份AI视觉项目启动的“现场手记”你看到的这行mkdir D:\模块Bcd /d D:\模块Bmkdir 任务一成果 任务二成果 任务三成果 任务四成果,表面看是Windows命令行里一串混乱的mkdir指令,甚至带点语法错误——它根本跑不通。但…

阅读更多 →
S7协议通信实战:从握手到数据读写的深度解析 2026/9/28 21:28:42

S7协议通信实战:从握手到数据读写的深度解析

1. 工控现场为什么要死磕S7协议搞工控的兄弟大多有过这种经历:产线上位机要采一批西门子PLC的数据,拿了个现成的库,连上能读,但偶尔断、偶尔慢、偶尔读回来的浮点数明显不对。翻日志只看到一句“连接超时”,剩下的全靠…

阅读更多 →
手写数字识别系统Python课设:CNN模型训练与部署指南 2026/9/28 21:28:21

手写数字识别系统Python课设:CNN模型训练与部署指南

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

阅读更多 →
ARTEMIS 视觉驱动移动端自动化:从架构到实战的完整指南 2026/9/28 21:28:14

ARTEMIS 视觉驱动移动端自动化:从架构到实战的完整指南

移动端自动化这个方向,过去几年一直有个尴尬的瓶颈:脚本能点、能滑、能截图,但一旦界面稍有变化,整套流程就崩了。传统方案靠的是控件树和固定坐标,本质上是在"背答案",而不是"理解题目&quo…

阅读更多 →
FPGA以太网硬件设计:RTL8211F与RGMII接口实战避坑指南 2026/9/28 21:28:14

FPGA以太网硬件设计:RTL8211F与RGMII接口实战避坑指南

1. 为什么RTL8211F在FPGA以太网项目里出镜率这么高搞FPGA以太网通信的兄弟,大概率都绕不开RTL8211F这颗PHY芯片。我第一次用它是在一个图像采集项目里,FPGA端需要把采集到的数据实时传到上位机,千兆带宽是硬指标,选型的时候翻了一…

阅读更多 →
CUDA版本匹配原理:驱动、Toolkit与PyTorch/TensorFlow的ABI兼容性 2026/9/28 21:28:14

CUDA版本匹配原理:驱动、Toolkit与PyTorch/TensorFlow的ABI兼容性

1. 为什么CUDA版本不匹配会直接让PyTorch/TensorFlow“装死”——从GPU驱动到框架ABI的完整断层链你刚配好一台RTX 4060 Laptop GPU的笔记本,兴冲冲跑通了nvidia-smi,显卡状态绿油油,驱动版本显示535.104.05,一切看起来都对。可一…

阅读更多 →

今日资讯

本周资讯

本月资讯

看完文章仍有疑问?

联系尧图顾问,获取一对一建站咨询

立即免费咨询 📞 400-888-8888
📞 ✉