Mybatis-Plus中的selectByMap使用實(shí)例
前言:
我在開始用Mybatis-Plus來對數(shù)據(jù)庫進(jìn)行增刪改查時,將里面的函數(shù)試了個遍,接下來我就將使用selectByMap函數(shù)的簡單測試實(shí)例寫出來,方便沒有使用過的朋友們快速上手
正文:
首先我們要使用這個selectByMap函數(shù),需要在我們的Mapper中繼承mybatis-plus包中相應(yīng)的接口
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中接口就有該函數(shù):
// 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調(diào)用的就是其中的函數(shù)。
接下來就是調(diào)用的方法:
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注解是表示這是一個測試類,可以單獨(dú)拎出來測試。
這條語句是,將查到的student_code為123456的那一行信息拿出來并打印在控制臺上。
這是數(shù)據(jù)庫中的相關(guān)信息:

這是運(yùn)行的結(jié)果:

這就是selectByMap函數(shù)最簡單基礎(chǔ)的用法,如果有什么寫得不對或者不夠充分的地方還請各位大佬指正補(bǔ)充,我也好跟著一起學(xué)習(xí)~~
到此這篇關(guān)于Mybatis-Plus中的selectByMap使用實(shí)例的文章就介紹到這了,更多相關(guān)Mybatis-Plus selectByMap內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java中對象的深復(fù)制(深克?。┖蜏\復(fù)制(淺克?。┙榻B
這篇文章主要介紹了Java中對象的深復(fù)制(深克隆)和淺復(fù)制(淺克?。?,需要的朋友可以參考下2015-03-03
spring @Scheduled定時任務(wù)注解使用方法及注意事項小結(jié)
Spring的@Scheduled注解用于定時任務(wù)調(diào)度,默認(rèn)單線程依次執(zhí)行,可以通過配置多線程調(diào)度器或使用@Async注解實(shí)現(xiàn)并行執(zhí)行,常見參數(shù)包括cron、fixedRate、fixedDelay、initialDelay等,本文介紹spring @Scheduled定時任務(wù)注解使用方法,感興趣的朋友一起看看吧2025-02-02
SpringBoot中處理的轉(zhuǎn)發(fā)與重定向方式
這篇文章主要介紹了SpringBoot中處理的轉(zhuǎn)發(fā)與重定向方式,分別就轉(zhuǎn)發(fā)和重定向做了概念解說,結(jié)合示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-11-11
springboot實(shí)現(xiàn)用戶名查找用戶功能
本文主要介紹了springboot實(shí)現(xiàn)用戶名查找用戶功能,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04

