Parcourir la source

test update router

xiongzhu il y a 7 ans
Parent
commit
1ffae7a20b

+ 3 - 2
src/main/java/com/izouma/awesomeadmin/web/GenCodeController.java

@@ -2,6 +2,7 @@ package com.izouma.awesomeadmin.web;
 
 import java.io.File;
 import java.util.*;
+import java.util.regex.Pattern;
 
 import com.google.gson.Gson;
 import com.izouma.awesomeadmin.model.GenCode;
@@ -85,7 +86,7 @@ public class GenCodeController extends BaseController {
     @ResponseBody
     public Result save(@RequestBody GenCode record) {
         try {
-            Gson gson=new Gson();
+            Gson gson = new Gson();
             record.setGenJson(gson.toJson(record));
             genCode(record);
 
@@ -105,7 +106,7 @@ public class GenCodeController extends BaseController {
     @ResponseBody
     public Result updateGenCode(@RequestBody GenCode record) {
         try {
-            Gson gson=new Gson();
+            Gson gson = new Gson();
             record.setGenJson(gson.toJson(record));
             genCode(record);
 

+ 29 - 2
src/test/java/GenCodeTest.java

@@ -2,6 +2,8 @@ import org.apache.commons.lang.StringUtils;
 import org.junit.Test;
 
 import java.io.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 public class GenCodeTest {
     @Test
@@ -20,8 +22,8 @@ public class GenCodeTest {
 
             int insertLocation = routerJs.indexOf("/**INSERT_LOCATION**/");
             if (insertLocation > -1) {
-                String routeName =   StringUtils.capitalize(className);
-                String routePath =  StringUtils.uncapitalize(className);
+                String routeName = StringUtils.capitalize(className);
+                String routePath = StringUtils.uncapitalize(className);
                 String route = "{\n                    path: '/"
                         + routePath
                         + "',\n                    name: '"
@@ -46,4 +48,29 @@ public class GenCodeTest {
             e.printStackTrace();
         }
     }
+
+    @Test
+    public void testUpdateRouter() {
+        try {
+            File file = new File("/Users/drew/Projects/Java/awesomeAdmin/src/main/vue/src/router", "index.js");
+            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
+            StringBuilder routerJs = new StringBuilder();
+            String line = null;
+            while ((line = reader.readLine()) != null) {
+                routerJs.append(line).append("\n");
+            }
+            reader.close();
+
+//            Pattern pattern = Pattern.compile("\\{[ \\n]*path:[ \\n]*'/404',[ \\n]*name:[ \\n]*'404',[ \\n]*component:[ \\n]*\\([ \\n]*\\)[ \\n]*=>[ \\n]*import\\('\\.\\./pages/404'\\)[ \\n]*}");
+            Pattern pattern = Pattern.compile("'/404");
+            Matcher matcher = pattern.matcher(routerJs.toString());
+            if (matcher.find()) {
+                System.out.println(">>>" + matcher.start());
+
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
 }