mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
ff382aff85
commit
9d3551389e
@ -321,7 +321,7 @@ public class Dict extends CustomKeyMap<String, Object> implements TypeGetter<Str
|
||||
* @return Dict 结果
|
||||
* @since 4.0.10
|
||||
*/
|
||||
public Dict filter(final String... keys) {
|
||||
public Dict filterNew(final String... keys) {
|
||||
final Dict result = new Dict(keys.length, 1);
|
||||
|
||||
for (final String key : keys) {
|
||||
@ -332,6 +332,17 @@ public class Dict extends CustomKeyMap<String, Object> implements TypeGetter<Str
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤Map去除指定键值对,如果键不存在跳过
|
||||
*
|
||||
* @param keys 键列表
|
||||
* @return Dict 结果
|
||||
* @since 4.0.10
|
||||
*/
|
||||
public Dict removeNew(final String... keys) {
|
||||
return MapUtil.removeAny(this.clone(), keys);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------- Set start
|
||||
|
||||
/**
|
||||
|
@ -951,13 +951,13 @@ public class MapUtil extends MapGetUtil {
|
||||
*
|
||||
* @param <K> Key类型
|
||||
* @param <V> Value类型
|
||||
* @param <T> Map类型
|
||||
* @param map Map
|
||||
* @param keys 键列表
|
||||
* @return 修改后的key
|
||||
* @since 5.0.5
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <K, V> Map<K, V> removeAny(final Map<K, V> map, final K... keys) {
|
||||
public static <K, V, T extends Map<K, V>> T removeAny(final T map, final K... keys) {
|
||||
for (final K key : keys) {
|
||||
map.remove(key);
|
||||
}
|
||||
|
@ -83,4 +83,16 @@ public class DictTest {
|
||||
private String username;
|
||||
private String nickname;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeNewTest(){
|
||||
final Dict dict = Dict.of()
|
||||
.set("key1", 1)//int
|
||||
.set("key2", 1000L)//long
|
||||
.set("key3", DateTime.now());//Date
|
||||
|
||||
final Dict dict2 = dict.removeNew("key1");
|
||||
Assertions.assertEquals(3, dict.size());
|
||||
Assertions.assertEquals(2, dict2.size());
|
||||
}
|
||||
}
|
||||
|
@ -145,9 +145,9 @@ public class DialectRunner implements Serializable {
|
||||
* @throws DbRuntimeException SQL执行异常
|
||||
*/
|
||||
public int insertOrUpdate(final Connection conn, final Entity record, final String... keys) throws DbRuntimeException {
|
||||
final Entity where = record.filter(keys);
|
||||
final Entity where = record.filterNew(keys);
|
||||
if (MapUtil.isNotEmpty(where) && count(conn, Query.of(where)) > 0) {
|
||||
return update(conn, record, where);
|
||||
return update(conn, record.removeNew(keys), where);
|
||||
} else {
|
||||
return insert(conn, record)[0];
|
||||
}
|
||||
|
@ -107,7 +107,10 @@ public class Entity extends Dict {
|
||||
/* 字段名列表,用于限制加入的字段的值 */
|
||||
private Set<String> fieldNames;
|
||||
|
||||
// --------------------------------------------------------------- Constructor start
|
||||
// region ----- Constructor
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public Entity() {
|
||||
}
|
||||
|
||||
@ -132,7 +135,7 @@ public class Entity extends Dict {
|
||||
super(caseInsensitive);
|
||||
this.tableName = tableName;
|
||||
}
|
||||
// --------------------------------------------------------------- Constructor end
|
||||
// endregion
|
||||
|
||||
// --------------------------------------------------------------- Getters and Setters start
|
||||
|
||||
@ -259,7 +262,7 @@ public class Entity extends Dict {
|
||||
* @since 4.0.10
|
||||
*/
|
||||
@Override
|
||||
public Entity filter(final String... keys) {
|
||||
public Entity filterNew(final String... keys) {
|
||||
final Entity result = new Entity(this.tableName);
|
||||
result.setFieldNames(this.fieldNames);
|
||||
|
||||
@ -271,6 +274,11 @@ public class Entity extends Dict {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity removeNew(final String... keys) {
|
||||
return (Entity) super.removeNew(keys);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------- Put and Set start
|
||||
@Override
|
||||
public Entity set(final String field, final Object value) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user