根据某个或者多个非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); }); }
通过其他字段批量更新或新增
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文档到电脑,方便收藏和打印~
2024-04-01
2024-04-03
2024-04-03
2024-01-21
2024-01-21
2024-01-21
2024-01-21
2023-12-23
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0