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
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值