去掉controller不用的URL





/**  
 * @ClassName Test
 * @Description TODO(去掉没有用的接口)
 * @author feizhou
 * @Date 2018年5月9日 下午3:41:31
 * @version 1.0.0
 */
public class Test {
private static  Set<String> urls=new HashSet<String>();
private static  Set<String> jsurls=new HashSet<String>();
//获取java文件的所有@RequestMapping(value = "/account/findAccounts.do")的url
//  存在在集合中 list<url>
    //获取页面的所有js,
    //url : '/upload/findFileUpload.do',
    /*$(function() {   
    showFileGrid();
//  showProcessGrid();  

});*/



    public static void main(String[] args) throws Exception {
        String controllerPath="D:\\workspace\\money\\src\\main\\java\\cn\\xiniu\\core\\controller";
        String jsPath="D:\\workspace\\money\\src\\main\\webapp\\js";
        File srcFile =new File(controllerPath);
        readControllerFiles(srcFile);
        File jsPathsrc =new File(jsPath);
        readJsFiles(jsPathsrc);
        String dest="D:\\test\\urls.txt";
        writeUnUsedUrl(dest);
    }


    /**
     * 
     * @Description (获取controller的所有映射URl)
     * @author feizhou
     * @Date 2018年5月9日下午4:03:24  
     * @version 1.0.0
     * @param src
     * @throws IOException
     */
    public  static void  getUrl(File src) throws IOException{

        BufferedReader reader = new BufferedReader(new FileReader(src));
        String line = null;
        while ((line = reader.readLine()) != null) {
         //当前行操作
            String newLine=line.trim();
            if(newLine.startsWith("//")){
             continue;
            }
            if(newLine.contains("@RequestMapping(")){
                newLine=newLine.replace("@RequestMapping(", "");
                newLine=newLine.replace(")", "");
                newLine=newLine.replace("value", "");
                newLine=newLine.replace("=", "");
                newLine=newLine.replace("\"", "");
                newLine=newLine.replace("\'", "");
                newLine=newLine.trim();
                System.out.println("当前的RequestMapping: "+newLine);
                urls.add(newLine);
            }
        }
    }
/**
 * 
 * @Description (读取controller的所有文件)
 * @author feizhou
 * @Date 2018年5月9日下午4:01:50  
 * @version 1.0.0
 * @param srcFile
 * @param destFile
 * @throws IOException
 */
@SuppressWarnings("unused")
private static void readControllerFiles(File srcFile)
        throws IOException {
    if (srcFile.isDirectory()) { //是目录

        // 获取该File对象下的所有文件或者文件夹File对象

        File[] fileArray = srcFile.listFiles();
        //递归操作
        for (File file : fileArray) {
            //子文件,重复copyFolder
            readControllerFiles(file);
        }
    } else {
      //是文件
        getUrl(srcFile);
    }
}

@SuppressWarnings("unused")
private static void readJsFiles(File srcFile)
        throws IOException {
    if (srcFile.isDirectory()) { //是目录

        // 获取该File对象下的所有文件或者文件夹File对象

        File[] fileArray = srcFile.listFiles();
        //递归操作
        for (File file : fileArray) {
            //子文件,重复copyFolder
            readJsFiles(file);
        }
    } else {
      //是文件
        readJsFile(srcFile);
    }
}
public  static void  readJsFile(File src) throws IOException{

    BufferedReader reader = new BufferedReader(new FileReader(src));
    String line = null;
    while ((line = reader.readLine()) != null) {
     //当前行操作
        String newLine=line.trim();
        if(newLine.startsWith("//")){
         continue;
        }
        isContains(newLine);
    }
}

public static void isContains(String line){
     Iterator<String> keys = urls.iterator();
     while(keys.hasNext()){
         String url=keys.next();
         if(line.contains(url)){
             jsurls.add(url);
         }
     }
}

public static void writeUnUsedUrl(String dest) throws IOException{
    //去掉已存在的url
     Iterator<String> keys = jsurls.iterator();
     while(keys.hasNext()){
         String url=keys.next();
         if(url.contains("/financial/moneyPaymentController/bankSave")){
             System.out.println(url);
         }
         urls.remove(url);
     }
     fileToFileByBuffString(urls, dest);

}

public static void fileToFileByBuffString(Set<String> urls,String dest) throws IOException{

    BufferedWriter bw=new BufferedWriter(new FileWriter(dest));

    //没有用的url写到文件中
     Iterator<String> urlskey = urls.iterator();
     while(urlskey.hasNext()){
         String url=urlskey.next();
          bw.write(url);
          bw.newLine();
          bw.flush();
     }

    bw.close();
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
文件(E)编辑(E) 视图(M) 导航(N) 代码(C) 重构(R) 构建(B) 运行(山) 工具(I) Git(G) 窗口W) 帮助(H) 瑞 吉外卖[D:\瑞吉外卖] - applicationyml [untitled] 吊截图工具 里▼人L临Application▼>在CC▼■|Git(G);kV入+0。 吊新建(N) 模式M)▼C 3延迟(D) ▼X取消(Q) 瑞吉外卖〉 untitled ) src ) main ) resources ) 6 application.yml 项目 朵王云交-Cotoller.java X C SetmealContoller.java ShopingCarContollerjava xe UserConrtollerjava xm pom.xml (ntited)使用’模式'按钮选择截图模式,或单击新建’按钮。 java spring: 截图工具正在移动.. 口com D itheima application: 在将来的更新,截图工具将移到新的家。尝试改进的功 v D common #设置开发当前应用的名称 使用截图和草图(&S)(或尝试快捷方式Windows徽标键 9 BaseCantext name: reggie_ _take_ out Shift + S)像往常一样进行截图。 P CustomException 。GlobalExceptionHandler datasource: #设置数据源以及连接配置 试用”截图和草图” 。JacksonObjectMapper druid: MyMetaObjecthandler driver- cLass-name: com . mysqL. cj. jdbc . Driver b config 1 urL: jdbc:mysqL://locaLhost:3306/ ruiji?serverTimezone=Asia/ Shanghai&useUnicode=true&characterEncoding=utf MybatisPlusConfig username: root RedisConfig 3 password: jqL1*9700 O WebMvcConfig 4 redis: v D controller C AddresBookController 5 host: 192. 168.200.129 #ip CategoryController 6 port: 6379 #端口 CommonController 9 DishController 17 password: root@123456 #密码 没设密码的话不用写 ◎EmployeeController 8 database: 0 #连接数 ◎OrderController 9 OrderDetailController 9 SetmealController 0 mybatis -pLus: 9 ShoppingCartController 21 configuration: 9 UserController 2 #在映射实体或者属性时,将数据库表名和字段名的下划线去掉,按照驼峰命名法映射 ,. entity map-underscore-to- camel-case: true #设置为truel时t:可以用驼峰命名法->->->数据库 表名为xaddress_ book ,那么实 9 AddressBook 4 Log- impL: org. apache . ibatis . Logging. stdout. Stdout ImpL #控制台打印sqL日志 Category 25 gLobaL-config: Dish 。DishFlavor 26 db-config: Employee 7 id-type: ASSIGN_ ID #配置 主键生成策略 OrderDetail Document1/1 ) spring: 》 redis: , password: ) root@ 123456 a Arderc pGit>运行三TODO0问题CProfiler之Dependencies2终端八端点人构建.Spring a事件日志 构建大014三小tceth二11八幼之的 17.00.cnirutr。,入六坡量110 构建车25 18:28 0n果 O回后x 2023/3/10
最新发布
03-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值