From 402082f03865d8c008988a54a1f15d14055b98d6 Mon Sep 17 00:00:00 2001 From: "youhong.ai" Date: Fri, 12 May 2023 21:17:28 +0800 Subject: [PATCH] =?UTF-8?q?mapper=E6=8B=BC=E6=8E=A5=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/recordset/MapperBuilderSql.java | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/main/java/aiyh/utils/recordset/MapperBuilderSql.java b/src/main/java/aiyh/utils/recordset/MapperBuilderSql.java index 505711c..6f7eb38 100644 --- a/src/main/java/aiyh/utils/recordset/MapperBuilderSql.java +++ b/src/main/java/aiyh/utils/recordset/MapperBuilderSql.java @@ -23,6 +23,17 @@ public class MapperBuilderSql { * @return 构建的sql */ public static String builderUpdateSql(String table, Map param) { + return builderUpdateSql(table, param, ""); + } + + /** + *

构建更新sql

+ * + * @param table 表名称 + * @param param 参数 + * @return 构建的sql + */ + public static String builderUpdateSql(String table, Map param, String paramPrefix) { if (StrUtil.isBlank(table) || CollectionUtil.isEmpty(param)) { throw new CustomerException("tableName or param can not to be null!"); } @@ -32,8 +43,11 @@ public class MapperBuilderSql { sb.append(" ") .append(entry.getKey()) .append(" = ") - .append("#{") - .append(entry.getKey()) + .append("#{"); + if (StrUtil.isNotBlank(paramPrefix)) { + sb.append(paramPrefix).append("."); + } + sb.append(entry.getKey()) .append("}") .append(","); } @@ -49,6 +63,10 @@ public class MapperBuilderSql { * @return 构建的sql */ public static String builderInsertSql(String table, Map param) { + return builderInsertSql(table, param, ""); + } + + public static String builderInsertSql(String table, Map param, String paramPrefix) { if (StrUtil.isBlank(table) || CollectionUtil.isEmpty(param)) { throw new CustomerException("tableName or param can not to be null!"); } @@ -58,7 +76,11 @@ public class MapperBuilderSql { sbValue.append(") values ( "); for (Map.Entry entry : param.entrySet()) { sb.append(entry.getKey()).append(" ,"); - sbValue.append(" #{").append(entry.getKey()).append("},"); + sbValue.append(" #{"); + if (StrUtil.isNotBlank(paramPrefix)) { + sbValue.append(paramPrefix).append("."); + } + sbValue.append(entry.getKey()).append("},"); } sb.deleteCharAt(sb.length() - 1); sbValue.deleteCharAt(sbValue.length() - 1); @@ -66,6 +88,7 @@ public class MapperBuilderSql { return sb.toString(); } + public static String builderWhereAnd(Map param, boolean containsWhere) { return builderWhereAnd(param, "whereParam", containsWhere); }