diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c3a8d4cd..578913077 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,13 @@ # 🚀Changelog ------------------------------------------------------------------------------------------------------------- -# 5.8.19.M1 (2023-04-17) +# 5.8.19.M1 (2023-04-18) ### 🐣新特性 ### 🐞Bug修复 * 【core 】 修复URLUtil.decode无法解码UTF-16问题(issue#3063@Github) +* 【db 】 修复insertOrUpdate更新中条件字段没有移除问题(issue#I6W91Z@Gitee) ------------------------------------------------------------------------------------------------------------- # 5.8.18 (2023-04-16) diff --git a/hutool-db/src/main/java/cn/hutool/db/DialectRunner.java b/hutool-db/src/main/java/cn/hutool/db/DialectRunner.java index 74db2e257..a891f3ba8 100644 --- a/hutool-db/src/main/java/cn/hutool/db/DialectRunner.java +++ b/hutool-db/src/main/java/cn/hutool/db/DialectRunner.java @@ -129,7 +129,9 @@ public class DialectRunner implements Serializable { public int insertOrUpdate(Connection conn, Entity record, String... keys) throws SQLException { final Entity where = record.filter(keys); if (MapUtil.isNotEmpty(where) && count(conn, where) > 0) { - return update(conn, record, where); + // issue#I6W91Z + // 更新时,给定的字段无需更新 + return update(conn, record.removeNew(keys), where); } else { return insert(conn, record)[0]; } diff --git a/hutool-db/src/main/java/cn/hutool/db/Entity.java b/hutool-db/src/main/java/cn/hutool/db/Entity.java index 5afd8ca10..cd807c359 100755 --- a/hutool-db/src/main/java/cn/hutool/db/Entity.java +++ b/hutool-db/src/main/java/cn/hutool/db/Entity.java @@ -3,6 +3,7 @@ package cn.hutool.db; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.lang.Dict; import cn.hutool.core.lang.func.Func0; +import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.ReflectUtil; @@ -10,11 +11,7 @@ import cn.hutool.core.util.StrUtil; import cn.hutool.db.sql.SqlUtil; import java.nio.charset.Charset; -import java.sql.Blob; -import java.sql.Clob; -import java.sql.RowId; -import java.sql.Time; -import java.sql.Timestamp; +import java.sql.*; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -257,6 +254,17 @@ public class Entity extends Dict { 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 @Override public Entity set(String field, Object value) {