diff --git a/src/main/java/aiyh/utils/recordset/MapperBuilderSql.java b/src/main/java/aiyh/utils/recordset/MapperBuilderSql.java
new file mode 100644
index 0000000..13fff23
--- /dev/null
+++ b/src/main/java/aiyh/utils/recordset/MapperBuilderSql.java
@@ -0,0 +1,110 @@
+package aiyh.utils.recordset;
+
+import aiyh.utils.excention.CustomerException;
+import aiyh.utils.tool.cn.hutool.core.collection.CollectionUtil;
+import aiyh.utils.tool.cn.hutool.core.util.StrUtil;
+
+import java.util.Map;
+
+/**
+ *
构建sql
+ *
+ * create: 2023/5/12 20:51
+ *
+ * @author youHong.ai
+ */
+public class MapperBuilderSql {
+
+ /**
+ * 构建更新sql
+ *
+ * @param table 表名称
+ * @param param 参数
+ * @return 构建的sql
+ */
+ public static String builderUpdateSql(String table, Map param) {
+ if (StrUtil.isBlank(table) || CollectionUtil.isEmpty(param)) {
+ throw new CustomerException("tableName or param can not to be null!");
+ }
+ StringBuilder sb = new StringBuilder();
+ sb.append("update ").append(table).append(" set ");
+ for (Map.Entry entry : param.entrySet()) {
+ sb.append(" ")
+ .append(entry.getKey())
+ .append(" = ")
+ .append("#{")
+ .append(entry.getKey())
+ .append("}")
+ .append(",");
+ }
+ sb.deleteCharAt(sb.length() - 1);
+ return sb.toString();
+ }
+
+ /**
+ * 构建插入sql
+ *
+ * @param table 表名称
+ * @param param 参数
+ * @return 构建的sql
+ */
+ public static String builderInsertSql(String table, Map param) {
+ if (StrUtil.isBlank(table) || CollectionUtil.isEmpty(param)) {
+ throw new CustomerException("tableName or param can not to be null!");
+ }
+ StringBuilder sb = new StringBuilder();
+ StringBuilder sbValue = new StringBuilder();
+ sb.append("insert into ").append(table).append(" (");
+ sbValue.append(") values ( ");
+ for (Map.Entry entry : param.entrySet()) {
+ sb.append(entry.getKey()).append(" ,");
+ sbValue.append(" #{").append(entry.getKey()).append("},");
+ }
+ sb.deleteCharAt(sb.length() - 1);
+ sbValue.deleteCharAt(sbValue.length() - 1);
+ sb.append(sbValue).append(")");
+ return sb.toString();
+ }
+
+ public static String builderWhereAnd(Map param, boolean containsWhere) {
+ return builderWhereAnd(param, "whereParam", containsWhere);
+ }
+
+ public static String builderWhereAnd(Map param) {
+ return builderWhereAnd(param, "whereParam", true);
+ }
+
+ public static String builderNoWhereAndEn(Map param, boolean containsWhere) {
+ return builderWhereAnd(param, "", containsWhere);
+ }
+
+ public static String builderNoWhereAndEn(Map param) {
+ return builderWhereAnd(param, "", false);
+ }
+
+ /**
+ * 构建and条件
+ *
+ * @param param 参数
+ * @param wherePrefix 条件拼接前缀
+ * @param containsWhere 是否包含where
+ * @return 构建的where条件
+ */
+ public static String builderWhereAnd(Map param, String wherePrefix, boolean containsWhere) {
+ if (CollectionUtil.isEmpty(param)) {
+ throw new CustomerException("tableName or param can not to be null!");
+ }
+ StringBuilder sb = new StringBuilder();
+ if (containsWhere) {
+ sb.append(" where ");
+ }
+ for (Map.Entry entry : param.entrySet()) {
+ sb.append(entry.getKey()).append(" and ").append("#{");
+ if (StrUtil.isNotBlank(wherePrefix)) {
+ sb.append(wherePrefix).append(".");
+ }
+ sb.append(entry.getKey()).append("}");
+ }
+ return sb.toString();
+ }
+}
diff --git a/src/main/java/aiyh/utils/sqlUtil/builderSql/impl/BuilderSqlImpl.java b/src/main/java/aiyh/utils/sqlUtil/builderSql/impl/BuilderSqlImpl.java
index 8cf0589..82f14a0 100644
--- a/src/main/java/aiyh/utils/sqlUtil/builderSql/impl/BuilderSqlImpl.java
+++ b/src/main/java/aiyh/utils/sqlUtil/builderSql/impl/BuilderSqlImpl.java
@@ -5,18 +5,15 @@ import aiyh.utils.Util;
import aiyh.utils.mapUtil.UtilHashMap;
import aiyh.utils.mapUtil.UtilLinkedHashMap;
import aiyh.utils.sqlUtil.builderSql.BuilderSql;
-import aiyh.utils.sqlUtil.sqlResult.impl.PrepSqlResultImpl;
import aiyh.utils.sqlUtil.sqlResult.impl.BatchSqlResultImpl;
+import aiyh.utils.sqlUtil.sqlResult.impl.PrepSqlResultImpl;
import aiyh.utils.sqlUtil.whereUtil.Where;
import aiyh.utils.sqlUtil.whereUtil.impl.WhereImpl;
import weaver.conn.RecordSet;
-
import java.beans.BeanInfo;
-import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
-import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
@@ -29,15 +26,16 @@ import java.util.stream.Collectors;
public class BuilderSqlImpl implements BuilderSql {
- private String DB_TYPE;
-
+ private final String DB_TYPE;
+
{
// 获取当前数据库的类型
this.DB_TYPE = (new RecordSet()).getDBType();
}
-
+
/**
* 构建插入语句
+ *
* @param tableName 数据库表名
* @param mapConfig 数据库字段和值
* @return 自定义SQL实体类
@@ -63,21 +61,22 @@ public class BuilderSqlImpl implements BuilderSql {
sqlBuilder.append(" )");
return new PrepSqlResultImpl(sqlBuilder.toString(), args);
}
-
- /**
- * 通过实体类构建插入SQL
- * @param tableName 数据库表名
- * @param t 实体类对象
- * @param 实体类对象泛型
- * @return SQL结果对象
- */
- public PrepSqlResultImpl insertSqlByEntity(String tableName, T t){
+
+ /**
+ * 通过实体类构建插入SQL
+ *
+ * @param tableName 数据库表名
+ * @param t 实体类对象
+ * @param 实体类对象泛型
+ * @return SQL结果对象
+ */
+ public PrepSqlResultImpl insertSqlByEntity(String tableName, T t) {
List