欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 时评 > MyBatis Plus 中常用的 Service 功能

MyBatis Plus 中常用的 Service 功能

2025/5/22 10:29:18 来源:https://blog.csdn.net/weixin_46597615/article/details/145298185  浏览:    关键词:MyBatis Plus 中常用的 Service 功能

save():插入单条数据

service.save(entity);

removeById():根据 ID 删除数据。

service.removeById(id);

updateById():根据 ID 更新单条数据。

service.updateById(entity);

getById():根据 ID 查询单条数据。

service.getById(id);

list():查询所有数据。

service.list();

saveBatch():批量插入数据。

service.saveBatch(list);

removeBatchByIds():批量根据 ID 删除数据。

service.removeBatchByIds(ids);

page():分页查询。需要传入一个 Page 对象

Page<User> page = new Page<>(1, 10); // 当前页、每页条数
IPage<User> userPage = service.page(page, null); // 第二个参数是查询条件,可以为 null

QueryWrapper:用于构建查询条件。

QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("age", 25).like("name", "John");
List<User> users = service.list(queryWrapper);

UpdateWrapper:用于构建更新条件

UpdateWrapper<User> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("name", "John").set("age", 30);
service.update(updateWrapper);

updateBatchById():批量更新

service.updateBatchById(list);

saveOrUpdateBatch():批量保存或更新。

service.saveOrUpdateBatch(list);

updateBatchById():批量更新。

service.updateBatchById(list);

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词