mybatisPlus封装的方法

一.CURD接口

Mapper CURD接口

1.int insert(T entity) //插入一条数据

2.deleteById(Serializable id)//根据ID删除

3.deleteByMap(Map<String,Object>columnMap)//根据columMap条件删除记录

4.int delete(Wrapper<T> Wrapper)//根据wrapper里面的Entity条件删除

5.int deleteBatchIds(Collection<? extends Serializable> idList);//根据id批量删除

6.int updateById(T entity)//根据id修改

7.int update(T entity, Wrapper<T> updateWrapper)//entity 作为set条件值,updateWrapprt里面的entity用于生成where条件值

8.T selectById(String id)//根据id查询

9.List<T> selectBatchIds(Collection<? extends Serializable> idList)//根据id批量查询

10.List<T> selectMap(Map<String,Object> columnMap)//根据map条件查询

11.T selectOne(Wrapper<T> queryWrapper);//根据wrapper里面的Entity查找,如果不是唯一需	要添加wrapper.last("limit 1 ")

12.Integer selectCount(Wrapper<T> queryWrapper)//根据wrapper条件查询总数

13.List<T> selectList(Wrapper<T> queryWrapper)//根据条件查询实体集合

14.List<Map<String,Object>> selectMaps (Wrapper<T> queryWrapper)//根据wrapper条件,查询全部记录

15.Page<T> selectPage(IPage<T> Page,Wrapper<T> queryWrapper)//返回实体分页对象

16.IPage<Map<String,Object>> selectMapsPage(IPage<T> Page,Wrapper<T> queryWrapper)//返回字段映射对象Map分页对象

二.Service CURD接口

1.boolean save(T entity);

2.boolean saveBatch(Collection<T> entityList);

3.boolean saveBatch(Collection<T> entityList, int batchSize);//batchSize每次的数量

4.boolean saveOrUpdateBatch(Collection<T> entityList);//批量修改插入

5.boolean saveOrUpdateBatch(Collection<T> entityList, int batchSize);

6.boolean removeById(Serializable id);

7.boolean removeByMap(Map<String, Object> columnMap);

8.boolean remove(Wrapper<T> queryWrapper);//queryWrapper 实体包装类,根据entuty条件删除

9.boolean removeByIds(Collection<? extends Serializable> idList);

10.boolean updateById(T entity);

11.boolean update(T entity, Wrapper<T> updateWrapper);

12.boolean updateBatchById(Collection<T> entityList, int batchSize);//批量更新

13.boolean saveOrUpdate(T entity);//TableId 注解存在更新记录,否插入一条记录

14.T getById(Serializable id);//根据id查询

15.Collection<T> listByIds(Collection<? extends Serializable> idList);//查询(根据ID 批量查询)

16.Collection<T> listByMap(Map<String, Object> columnMap);

17.Map<String, Object> getMap(Wrapper<T> queryWrapper);//根据 Wrapper,查询一条记录

18.Object getObj(Wrapper<T> queryWrapper);//根据 Wrapper,查询一条记录

19.int count(Wrapper<T> queryWrapper);//根据 Wrapper 条件,查询总记录数

20.List<T> list(Wrapper<T> queryWrapper);//查询列表

21.IPage<T> page(IPage<T> page, Wrapper<T> queryWrapper);//page为翻页对象

22.List<Map<String, Object>> listMaps(Wrapper<T> queryWrapper);//查询列表

23.List<Object> listObjs(Wrapper<T> queryWrapper);//根据 Wrapper 条件,查询全部记录

24.IPage<Map<String, Object>> pageMaps(IPage<T> page, Wrapper<T> queryWrapper);

三.常用方法

1.修改指定值
UpdateWrapper<User> userUpdateWrapper = new UpdateWrapper<>();
userUpdateWrapper.eq("userName","admin");
int update = Mapper.update(user,userUpdateWrapper);

2.查询不为空
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("userName","admin");
queryWrapper.isNotNull("userName");

3.查询指定列
QueryWrapper query = new QueryWrapper();
query.select("id","userName");

4.存在||不存在
AbstractWrapper queryTags = new QueryWrapper<>();
queryTags.in("id",ids);
List<PubTag> pubTagList = pubTagService.list(queryTags);

5.批量删除
String[] ids = ids.split(",");
List<String> idList = Arrays.asList(ids);
eventSercice.removeByIds(idList);
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MybatisPlus是一个优秀的ORM框架,它提供了一系列封装方法来简化数据库操作。根据提供的引用内容,我可以看到其中涉及到了三个MybatisPlus的封装方法。 引用\[1\]展示了使用MybatisPlus的list方法,该方法用于查询符合条件的数据列表。在这个例子中,使用了QueryWrapper来构建查询条件,其中包括了身份为2或3、is_topic为1、del_flag为0的条件,并按照topic_no升序排序,最后限制返回结果的数量为3。 引用\[2\]展示了使用MybatisPlus的remove方法,该方法用于删除符合条件的数据。在这个例子中,使用了QueryWrapper来构建删除条件,其中包括了care_user等于appUserCare.getCareUser()并且appuser_id等于userId的条件。 引用\[3\]展示了使用MybatisPlus的getMap方法,该方法用于查询符合条件的数据并返回一个Map对象。在这个例子中,使用了QueryWrapper来构建查询条件,其中包括了appuser_id等于userId、type等于2、balance_type不等于5以及create_time在指定的时间范围内的条件。最后通过select方法选择需要返回的字段,并使用getMap方法获取查询结果中的total字段值。 这些是MybatisPlus封装的一些常用方法,可以根据具体的需求选择合适的方法来进行数据库操作。 #### 引用[.reference_title] - *1* *2* *3* [mybatisplus封装方法](https://blog.csdn.net/weixin_42671581/article/details/130374664)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值