Selaa lähdekoodia

插入支持List

张泳健 5 vuotta sitten
vanhempi
commit
98bdae6d9d

+ 6 - 0
README.md Näytä tiedosto

@@ -11,6 +11,12 @@ java -jar db-data-to-csv-1.0.0.jar -t=TABLE_NAME
11 11
 ```
12 12
 参数说明:
13 13
 1. `-t=` / `--table=` 这两个指定导出的表名.
14
+2. `--size`: 指定分页大小
15
+3. `--truncate=true`: 插入数据前清空表
16
+4. `--type=mysql` 类型
17
+    - mysql: 拼语句
18
+    - mysqlps: 不拼语句
19
+    - csv: 导出到csv文件
14 20
 
15 21
 
16 22
 

+ 17 - 0
src/main/java/com/vcarecity/cvs/FileExporterApp.java Näytä tiedosto

@@ -54,10 +54,14 @@ public class FileExporterApp {
54 54
             properties = basePath;
55 55
         }
56 56
 
57
+        final int pageCount = getPageCount(args);
58
+
57 59
 
58 60
         injector = Guice.createInjector(new PropertiesModule(appProperties), new SQLModule(type));
59 61
 
60 62
         final SQLStarter instance = injector.getInstance(SQLStarter.class);
63
+        instance.setPageCount(pageCount);
64
+
61 65
         instance.exportDataAndConvert(table, properties, tableClass, isTruncate);
62 66
     }
63 67
 
@@ -85,6 +89,19 @@ public class FileExporterApp {
85 89
         return null;
86 90
     }
87 91
 
92
+    private static int getPageCount(String[] args) {
93
+        for (String arg : args) {
94
+            if (arg.startsWith("--size=")) {
95
+                try {
96
+                    return Integer.parseInt(arg.substring("--size=".length()));
97
+                } catch (RuntimeException e) {
98
+
99
+                }
100
+            }
101
+        }
102
+        return 10000;
103
+    }
104
+
88 105
 
89 106
     private static boolean jdbcArgs(String[] args, AppProperties properties) {
90 107
         final DbProperties database = properties.getFromDb();

+ 3 - 0
src/main/java/com/vcarecity/cvs/starter/SQLStarter.java Näytä tiedosto

@@ -20,6 +20,9 @@ import static com.vcarecity.cvs.FileExporterApp.TABLE_COLUMN;
20 20
 @Slf4j
21 21
 public class SQLStarter {
22 22
 
23
+    /**
24
+     * default
25
+     */
23 26
     private static final int PAGE_COUNT = 10000;
24 27
 
25 28
     private int pageCount = PAGE_COUNT;