iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > JAVA >Mybatis-plus通过其他字段批量更新或新增
  • 232
分享到

Mybatis-plus通过其他字段批量更新或新增

mybatisjava 2023-10-26 14:10:53 232人浏览 八月长安
摘要

根据某个或者多个非ID字段进行批量更新 示例通过名称与id两个字段更新 @Override public boolean updateBatchByColumn(List list) {

根据某个或者多个非ID字段进行批量更新

示例通过名称与id两个字段更新

    @Override    public boolean updateBatchByColumn(List<TestTable> list) {        return updateBatchByQueryWrapper(list, item->new QueryWrapper<>().eq("name",item.getName()).eq("id",item.getId()));    }    @Transactional(rollbackFor = Exception.class)    public boolean updateBatchByQueryWrapper(Collection<TestTable> entityList, Function<TestTable, QueryWrapper> wrapperFunction) {        String sqlStatement = this.getSqlStatement(SqlMethod.UPDATE);        return this.executeBatch(entityList, DEFAULT_BATCH_SIZE, (sqlSession, entity) -> {            Map<String, Object> param = CollectionUtils.newHashMapWithExpectedSize(2);            param.put(Constants.ENTITY, entity);            param.put(Constants.WRAPPER, wrapperFunction.apply(entity));            sqlSession.update(sqlStatement, param);        });    }

引用mybatis-plus根据某个指定字段批量更新数据库


通过其他字段批量更新或新增

     public boolean saveOrUpdateBatchByColumn(Collection<TestTable> entityList, Function<TestTable, QueryWrapper> function ) {        return SqlHelper.saveOrUpdateBatch(this.entityClass, this.mapperClass, LogFactory.getLog(AvgRowSub.class), entityList, 1000, (sqlSession, entity) -> {            Map<String, Object> param = Maps.newHashMap();            param.put(Constants.ENTITY, entity);            param.put(Constants.WRAPPER, function.apply(entity));            return CollectionUtils.isEmpty(sqlSession.selectList(this.getSqlStatement(SqlMethod.SELECT_MAPS), param));        }, (sqlSession, entity) -> {            Map<String, Object> param = Maps.newHashMap();            param.put(Constants.ENTITY, entity);            param.put(Constants.WRAPPER, function.apply(entity));            sqlSession.update(this.getSqlStatement(SqlMethod.UPDATE), param);        });    }

来源地址:https://blog.csdn.net/qq_43383907/article/details/129225531

--结束END--

本文标题: Mybatis-plus通过其他字段批量更新或新增

本文链接: https://www.lsjlt.com/news/462621.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作