前言:
我在开始用Mybatis-Plus来对数据库进行增删改查时,将里面的函数试了个遍,接下来我就将使用selectByMap函数的简单测试实例写出来,方便没有使用过的朋友们快速上手
正文:
首先我们要使用这个selectByMap函数,需要在我们的Mapper中继承mybatis-plus包中相应的接口
?
1
2
3
4
5
6 |
package com.example.library.Mapper;
import com.example.library.entity.bookBorrowing;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
public interface borrowMapper extends BaseMapper<bookBorrowing>{
} |
其中BaseMapper中接口就有该函数:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 |
// IntelliJ API Decompiler stub source generated from a class file
// Implementation of methods is not available
package com.baomidou.mybatisplus.core.mapper;
public interface BaseMapper <T> extends com.baomidou.mybatisplus.core.mapper.Mapper<T> {
int insert(T entity);
int deleteById(java.io.Serializable id);
int deleteByMap( @org .apache.ibatis.annotations.Param( "cm" ) java.util.Map<java.lang.String,java.lang.Object> columnMap);
int delete( @org .apache.ibatis.annotations.Param( "ew" ) com.baomidou.mybatisplus.core.conditions.Wrapper<T> queryWrapper);
int deleteBatchIds( @org .apache.ibatis.annotations.Param( "coll" ) java.util.Collection<? extends java.io.Serializable> idList);
int updateById( @org .apache.ibatis.annotations.Param( "et" ) T entity);
int update( @org .apache.ibatis.annotations.Param( "et" ) T entity, @org .apache.ibatis.annotations.Param( "ew" ) com.baomidou.mybatisplus.core.conditions.Wrapper<T> updateWrapper);
T selectById(java.io.Serializable id);
java.util.List<T> selectBatchIds( @org .apache.ibatis.annotations.Param( "coll" ) java.util.Collection<? extends java.io.Serializable> idList);
java.util.List<T> selectByMap( @org .apache.ibatis.annotations.Param( "cm" ) java.util.Map<java.lang.String,java.lang.Object> columnMap);
T selectOne( @org .apache.ibatis.annotations.Param( "ew" ) com.baomidou.mybatisplus.core.conditions.Wrapper<T> queryWrapper);
java.lang.Integer selectCount( @org .apache.ibatis.annotations.Param( "ew" ) com.baomidou.mybatisplus.core.conditions.Wrapper<T> queryWrapper);
java.util.List<T> selectList( @org .apache.ibatis.annotations.Param( "ew" ) com.baomidou.mybatisplus.core.conditions.Wrapper<T> queryWrapper);
java.util.List<java.util.Map<java.lang.String,java.lang.Object>> selectMaps( @org .apache.ibatis.annotations.Param( "ew" ) com.baomidou.mybatisplus.core.conditions.Wrapper<T> queryWrapper);
java.util.List<java.lang.Object> selectObjs( @org .apache.ibatis.annotations.Param( "ew" ) com.baomidou.mybatisplus.core.conditions.Wrapper<T> queryWrapper);
<E extends com.baomidou.mybatisplus.core.metadata.IPage<T>> E selectPage(E page, @org .apache.ibatis.annotations.Param( "ew" ) com.baomidou.mybatisplus.core.conditions.Wrapper<T> queryWrapper);
<E extends com.baomidou.mybatisplus.core.metadata.IPage<java.util.Map<java.lang.String,java.lang.Object>>> E selectMapsPage(E page, @org .apache.ibatis.annotations.Param( "ew" ) com.baomidou.mybatisplus.core.conditions.Wrapper<T> queryWrapper);
} |
其中的selectByMap调用的就是其中的函数。
接下来就是调用的方法:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 |
package com.example.library;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import com.example.library.Mapper.*;
import com.example.library.entity.*;
import org.mybatis.spring.annotation.MapperScan;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@MapperScan ( "com/example/library/Mapper" )
@SpringBootTest
class LibraryApplicationTests {
@Autowired
private borrowMapper borrowMapper;
@Test
public void mapSelect(){
Map<String,Object> map = new HashMap<String, Object>();
map.put( "student_code" , "123456" );
List<bookBorrowing> stu = borrowMapper.selectByMap(map);
for (bookBorrowing s:stu){
System.out.println(s);
}
}
} |
@Test注解是表示这是一个测试类,可以单独拎出来测试。
这条语句是,将查到的student_code为123456的那一行信息拿出来并打印在控制台上。
这是数据库中的相关信息:
这是运行的结果:
这就是selectByMap函数最简单基础的用法,如果有什么写得不对或者不够充分的地方还请各位大佬指正补充,我也好跟着一起学习~~
到此这篇关于Mybatis-Plus中的selectByMap使用实例的文章就介绍到这了,更多相关Mybatis-Plus selectByMap内容请搜索快网idc以前的文章或继续浏览下面的相关文章希望大家以后多多支持快网idc!
原文链接:https://blog.csdn.net/weixin_51043896/article/details/120048771
相关文章
猜你喜欢
- 服务器租用价格怎么计算?服务器租用多少钱一年? 2025-05-27
- 云服务器的“弹性”体现在哪些方面? 2025-05-27
- 刀片服务器是什么 刀片服务器的主要特点 2025-05-27
- 利用FTP和计划任务自动备份网站数据和数据库 2025-05-27
- 服务器技术之硬件冗余技术 2025-05-27
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-27 58
-
2025-05-26 96
-
2025-05-27 40
-
2025-05-26 105
-
2025-05-27 19
热门评论