SpringCloud中怎么利用MyBatis-Plus实现CRUD
发表于:2024-10-28 作者:千家信息网编辑
千家信息网最后更新 2024年10月28日,SpringCloud中怎么利用MyBatis-Plus实现CRUD,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。1.添加Mybatis
千家信息网最后更新 2024年10月28日SpringCloud中怎么利用MyBatis-Plus实现CRUD
SpringCloud中怎么利用MyBatis-Plus实现CRUD,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
1.添加Mybatis-Plus依赖
com.baomidou
mybatis-plus-boot-starter
3.2.0
2.配置数据源
导入数据库的驱动 查看mysql版本 5.7.29
到maven仓库查看适用的mysql驱动,5.7的没有,8.0兼容5.7的,所以选择8.0的驱动
mysql
mysql-connector-java
8.0.17
3.配置MyBatis-Plus
添加application.yml 文件配置数据源
文件路径:/passjava-question/src/main/resources/application.yml
spring:
datasource:
driver-class-name:com.mysql.cj.jdbc.Driver
url:jdbc:mysql://129.211.188.xxx:3306/passjava_admin?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
username:root
password:xxx配置mapper映射文件路径
mybatis-plus:
mapper-locations: classpath:/mapper/**/*.xml
global-config:
db-config:
id-type: auto添加MapperScan注解
@MapperScan("com.jackson0714.passjava.question.dao")
@SpringBootApplication
publicclass PassjavaQuestionApplication {
public static void main(String[] args) {
SpringApplication.run(PassjavaQuestionApplication.class, args);
}
}
4.测试mybatis-plus的CRUD方法
创建类型为javaBasic的type表数据
@Autowired
TypeService typeService;
// 创建题目类型
@Test
void testCreateType() {
TypeEntity typeEntity = new TypeEntity();
typeEntity.setType("javaBasic");
typeService.save(typeEntity);
System.out.println("创建成功");
}更新id=1的表数据
// 更新type=jvm
@Test
void testUpdateType() {
TypeEntity typeEntity = new TypeEntity();
typeEntity.setId(1L);
typeEntity.setType("jvm");
typeService.updateById(typeEntity);
System.out.println("修改成功");
}查询id=1的表数据
// 查询题目类型
@Test
void testSelectType() {
ListtypeEntityList = typeService.list(new QueryWrapper ().eq("id",1L));
typeEntityList.forEach((item)-> {
System.out.println(item);
});
System.out.println("查询成功");
}
删除id=1的表数据
// 删除题目类型记录
@Test
void testRemoveType() {
typeService.removeById(1L);
System.out.println("删除成功");
}
看完上述内容,你们掌握SpringCloud中怎么利用MyBatis-Plus实现CRUD的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!
数据
类型
配置
成功
查询
方法
题目
更新
驱动
内容
文件
更多
路径
问题
束手无策
为此
仓库
原因
对此
技能
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
中恒电气软件开发
专业直销软件开发的博客
湖南客户管理软件开发平台
网络安全模式不够怎么办
asp 数据库连接失败
网络技术考研院校排名
软件开发答辩怎么说
网络安全 强化队伍建设
数据库中药品编号
南京警示教育展馆软件开发
新异奇邵武网络技术有限公司
本地服务器绑定域名
查询数据库用户登录密码
黄浦区一站式数据库服务商成本
怎样获取数据库的服务器
安卓手机下ios软件开发
软件开发快速原型模型是
无锡电商软件开发热线
测绘软件开发工程师是干啥的
网络安全的海报下载
美国软件开发工程师p2
盘点2019 网络安全事件
武大国家网络安全学院的校招
英雄联盟手游台服服务器正在维护
洛阳三年制计算机网络技术教程
查询数据库用户登录密码
天眼小说软件开发
数据库处理事务的原理
陕西非遗档案数据库
二十一世纪网络安全