gaozl 11 сар өмнө
parent
commit
b3921354f8

+ 41 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/untils/SqlUtil.java

@@ -0,0 +1,41 @@
+package com.lc.ibps.untils;
+
+import java.util.Map;
+
+public class SqlUtil {
+
+
+    public static String buildInsertSql(Map<String, Object> map , String tableName) throws Exception {
+        StringBuilder sql = new StringBuilder("insert into "+tableName+" (");
+        for (Object key : map.keySet()) {
+            sql.append(key).append(",");
+        }
+        sql.delete(sql.length()-1,sql.length());
+        sql.append(") values(");
+        for (Object val : map.values()) {
+            sql.append("'").append(val).append("'").append(",");
+        }
+        sql.delete(sql.length()-1,sql.length());
+        sql.append(")");
+        return sql.toString();
+    }
+
+    /**
+     * 主键重复时忽略
+     */
+    public static String buildInsertIgnorePrimarySql(Map<String, Object> map , String tableName) throws Exception {
+        StringBuilder sql = new StringBuilder("insert ignore into "+tableName+" (");
+        for (Object key : map.keySet()) {
+            sql.append(key).append(",");
+        }
+        sql.delete(sql.length()-1,sql.length());
+        sql.append(") values(");
+        for (Object val : map.values()) {
+            sql.append("'").append(val).append("'").append(",");
+        }
+        sql.delete(sql.length()-1,sql.length());
+        sql.append(")");
+        return sql.toString();
+    }
+
+}