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); }