Mybatis-Plus中的selectByMap使用實例
前言:
我在開始用Mybatis-Plus來對數(shù)據(jù)庫進行增刪改查時,將里面的函數(shù)試了個遍,接下來我就將使用selectByMap函數(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注解是表示這是一個測試類,可以單獨拎出來測試。
這條語句是,將查到的student_code為123456的那一行信息拿出來并打印在控制臺上。
這是數(shù)據(jù)庫中的相關(guān)信息:
這是運行的結(jié)果:
這就是selectByMap函數(shù)最簡單基礎(chǔ)的用法,如果有什么寫得不對或者不夠充分的地方還請各位大佬指正補充,我也好跟著一起學(xué)習(xí)~~
到此這篇關(guān)于Mybatis-Plus中的selectByMap使用實例的文章就介紹到這了,更多相關(guān)Mybatis-Plus selectByMap內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java實戰(zhàn)房屋租賃網(wǎng)的實現(xiàn)流程
讀萬卷書不如行萬里路,只學(xué)書上的理論是遠遠不夠的,只有在實戰(zhàn)中才能獲得能力的提升,本篇文章手把手帶你用java+SSM+jsp+mysql+maven實現(xiàn)一個房屋租賃網(wǎng)站,大家可以在過程中查缺補漏,提升水平2021-11-11Netty的Handler鏈調(diào)用機制及如何組織詳解
這篇文章主要為大家介紹了Netty的Handler鏈調(diào)用機制及如何組織示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-03-03springboot中validator數(shù)據(jù)校驗功能的實現(xiàn)
這篇文章主要介紹了springboot中validator數(shù)據(jù)校驗功能,校驗分為普通校驗和分組校驗,每種校驗方式通過實例代碼給大家介紹的非常詳細,需要的朋友可以參考下2021-10-10