xinyb
2022-06-15 2f75326ea70fe8e225df1db6f5a835f3806f09fb
提交 | 用户 | age
45dcf7 1 package com.yc.layoutIcon.newLayout.conterll;
X 2
3 import com.yc.help.utils.CallBackMsg;
4 import org.apache.commons.lang3.StringUtils;
5 import org.springframework.web.bind.annotation.RequestMapping;
6 import org.springframework.web.bind.annotation.RestController;
7
8 import javax.servlet.http.HttpServletRequest;
9 import java.io.File;
10 import java.util.ArrayList;
11 import java.util.List;
12
13 /**
14  * 44控件:大图标控件
15  *
16  * @USER: xinyb_
17  * @DATE: 2022-01-22 11:07
18  */
19 @RestController
20 @RequestMapping("/bigIcon")
21 public class BigIconConterll {
22
23     @RequestMapping("/pathName.do")
24     public CallBackMsg getBigIcon(String pathName, HttpServletRequest request) {
25         CallBackMsg msg = new CallBackMsg();
26         try {
27             if (StringUtils.isBlank(pathName)) {
28                 msg.setTreeError("图标指定路径不能为空,请检查初始值是否设置有值。");
29                 return msg;
30             }
31             String path = request.getServletContext().getRealPath(pathName);
32             File file = new File(path);
33             File[] files = file.listFiles();
34             if (files == null) {
35                 msg.setTreeError("未发现设置的图标路径,请检查初始值设置。");
36                 return msg;
37             }
38             List<String> list = new ArrayList<>();
39             getFile(files, pathName, list);
40             msg.setData(list);
41         } catch (Exception e) {
42             msg.setTreeError(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
43         }
44         return msg;
45     }
46
47     /**
48      * 遍历文件获取全部图标 xin 2022-1-24 16:25:35
49      * 递归操作
50      *
51      * @param files
52      * @param name
53      * @param list
54      */
55     private void getFile(File[] files, String name, List<String> list) {
56         for (File f : files) {
2f7532 57             if (f.isFile() && f.getName().lastIndexOf(".") != -1) {
45dcf7 58                 list.add(name + "/" + f.getName());
X 59             }
60             if (f.isDirectory()) {
61                 File[] files1 = f.listFiles();
62                 String pathName = name + "/" + f.getName();
63                 //这里进行递归操作
64                 getFile(files1, pathName, list);
65             }
66         }
67     }
68 }