From 68f964819e77f82afcd6ef655ffcbf1a49f35c42 Mon Sep 17 00:00:00 2001 From: mxd <838425805@qq.com> Date: Sun, 15 Aug 2021 16:48:36 +0800 Subject: [PATCH] =?UTF-8?q?`db`=E6=A8=A1=E5=9D=97=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=A9=BA=E5=80=BC=E6=96=B9=E6=B3=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../magicapi/modules/table/NamedTable.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/magic-api/src/main/java/org/ssssssss/magicapi/modules/table/NamedTable.java b/magic-api/src/main/java/org/ssssssss/magicapi/modules/table/NamedTable.java index f1e83e72..4acdba4e 100644 --- a/magic-api/src/main/java/org/ssssssss/magicapi/modules/table/NamedTable.java +++ b/magic-api/src/main/java/org/ssssssss/magicapi/modules/table/NamedTable.java @@ -10,9 +10,6 @@ import java.util.function.Function; import java.util.stream.Collectors; -/** - * @author - */ public class NamedTable { String tableName; @@ -38,6 +35,8 @@ public class NamedTable { boolean useLogic = false; + boolean withBlank = false; + Where where = new Where(this); public NamedTable(String tableName, SQLModule sqlModule, Function rowMapColumnMapper) { @@ -54,6 +53,12 @@ public NamedTable logic(){ return this; } + @Comment("更新空值") + public NamedTable withBlank(){ + this.withBlank = true; + return this; + } + @Comment("设置主键名,update时使用") public NamedTable primary(String primary) { return primary(primary, null); @@ -125,7 +130,10 @@ public NamedTable groupBy(@Comment("要分组的列") String... columns) { return this; } - private List> filterNotBlanks() { + private Collection> filterNotBlanks() { + if(this.withBlank){ + return this.columns.entrySet(); + } return this.columns.entrySet().stream() .filter(it -> StringUtils.isNotBlank(Objects.toString(it.getValue(), ""))) .collect(Collectors.toList()); @@ -144,7 +152,7 @@ public Object insert(@Comment("各项列和值") Map data) { if (this.defaultPrimaryValue != null && StringUtils.isBlank(Objects.toString(this.columns.getOrDefault(this.primary, "")))) { this.columns.put(this.primary, this.defaultPrimaryValue); } - List> entries = filterNotBlanks(); + Collection> entries = filterNotBlanks(); if (entries.isEmpty()) { throw new MagicAPIException("参数不能为空"); } @@ -281,13 +289,8 @@ public int update(@Comment("各项列和值") Map data, @Comment if (StringUtils.isNotBlank(this.primary)) { primaryValue = this.columns.remove(this.primary); } - List> entries = null; - if (!isUpdateBlank) { - entries = filterNotBlanks(); - } else { - entries = new ArrayList<>(this.columns.entrySet()); - } - + this.withBlank = isUpdateBlank; + List> entries = new ArrayList<>(filterNotBlanks()); if (entries.isEmpty()) { throw new MagicAPIException("要修改的列不能为空"); }