瀏覽代碼

导出单表和多表接口缺陷解决

zhulu 1 年之前
父節點
當前提交
1963e03e79

+ 2 - 1
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/controller/ExportSqlController.java

@@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletResponse;
@@ -39,7 +40,7 @@ public class ExportSqlController {
     }
 
     @GetMapping("/tables")
-    public void exportDataBase(HttpServletResponse response, List<String> tableNames){
+    public void exportDataBase(HttpServletResponse response,@RequestParam List<String> tableNames){
         try {
             exportSqlService.exportTables(response,tableNames);
         } catch (Exception e) {

+ 8 - 2
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/util/ExportDatabaseUtil.java

@@ -36,6 +36,8 @@ public class ExportDatabaseUtil {
 
             //写入table
             writeTable(tables,stmt,rs,bw);
+            bw.flush();
+            bw.close();
             // 关闭资源
             fw.close();
 
@@ -89,6 +91,8 @@ public class ExportDatabaseUtil {
 
             //写入table
             writeTable(tables,stmt,rs,bw,tableName);
+            bw.flush();
+            bw.close();
             // 关闭资源
             fw.close();
 
@@ -133,14 +137,16 @@ public class ExportDatabaseUtil {
             stmt = conn.createStatement();
 
             // 获取数据库表名
-            List<String> tables = getTables(stmt,rs);
+//            List<String> tables = getTables(stmt,rs);
 
 
             FileWriter fw = new FileWriter(file, false);
             BufferedWriter bw = new BufferedWriter(fw);
 
             //写入table
-            writeTable(tables,stmt,rs,bw,tableNames);
+            writeTable(tableNames,stmt,rs,bw,tableNames);
+            bw.flush();
+            bw.close();
             // 关闭资源
             fw.close();