mirror of
https://gitee.com/dromara/hutool.git
synced 2025-06-28 13:34:09 +08:00
修复insertOrUpdate更新中条件字段没有移除问题
This commit is contained in:
parent
ce1c0bab45
commit
b79e8ced7e
@ -2,12 +2,13 @@
|
|||||||
# 🚀Changelog
|
# 🚀Changelog
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.19.M1 (2023-04-17)
|
# 5.8.19.M1 (2023-04-18)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【core 】 修复URLUtil.decode无法解码UTF-16问题(issue#3063@Github)
|
* 【core 】 修复URLUtil.decode无法解码UTF-16问题(issue#3063@Github)
|
||||||
|
* 【db 】 修复insertOrUpdate更新中条件字段没有移除问题(issue#I6W91Z@Gitee)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.18 (2023-04-16)
|
# 5.8.18 (2023-04-16)
|
||||||
|
@ -129,7 +129,9 @@ public class DialectRunner implements Serializable {
|
|||||||
public int insertOrUpdate(Connection conn, Entity record, String... keys) throws SQLException {
|
public int insertOrUpdate(Connection conn, Entity record, String... keys) throws SQLException {
|
||||||
final Entity where = record.filter(keys);
|
final Entity where = record.filter(keys);
|
||||||
if (MapUtil.isNotEmpty(where) && count(conn, where) > 0) {
|
if (MapUtil.isNotEmpty(where) && count(conn, where) > 0) {
|
||||||
return update(conn, record, where);
|
// issue#I6W91Z
|
||||||
|
// 更新时,给定的字段无需更新
|
||||||
|
return update(conn, record.removeNew(keys), where);
|
||||||
} else {
|
} else {
|
||||||
return insert(conn, record)[0];
|
return insert(conn, record)[0];
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package cn.hutool.db;
|
|||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.lang.Dict;
|
import cn.hutool.core.lang.Dict;
|
||||||
import cn.hutool.core.lang.func.Func0;
|
import cn.hutool.core.lang.func.Func0;
|
||||||
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import cn.hutool.core.util.CharsetUtil;
|
import cn.hutool.core.util.CharsetUtil;
|
||||||
import cn.hutool.core.util.ReflectUtil;
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
@ -10,11 +11,7 @@ import cn.hutool.core.util.StrUtil;
|
|||||||
import cn.hutool.db.sql.SqlUtil;
|
import cn.hutool.db.sql.SqlUtil;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.sql.Blob;
|
import java.sql.*;
|
||||||
import java.sql.Clob;
|
|
||||||
import java.sql.RowId;
|
|
||||||
import java.sql.Time;
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -257,6 +254,17 @@ public class Entity extends Dict {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 过滤Map去除指定键值对,如果键不存在跳过
|
||||||
|
*
|
||||||
|
* @param keys 键列表
|
||||||
|
* @return Dict 结果
|
||||||
|
* @since 5.8.19
|
||||||
|
*/
|
||||||
|
public Entity removeNew(final String... keys) {
|
||||||
|
return (Entity) MapUtil.removeAny(this.clone(), keys);
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------- Put and Set start
|
// -------------------------------------------------------------------- Put and Set start
|
||||||
@Override
|
@Override
|
||||||
public Entity set(String field, Object value) {
|
public Entity set(String field, Object value) {
|
||||||
|
Loading…
Reference in New Issue
Block a user