需要导入excel或其他文件时使用。
{
"label": "导入Excel",
"align": "right",
"type": "button",
"actionType": "dialog",
"dialog": {
"title": "导入A程序Excel文件",
"body": {
"type": "form",
"api": "/report/apm/excel/handle",
"body": [{
"type": "input-file",
"name": "file",
"label": "File",
"accept": ".xlsx",
"receiver": "/report/apm/excel/upload",
"drag": true
}]
}
}
}
"api": "/report/apm/excel/handle",
@ResponseBody
@RequestMapping("/apm/excel/handle")
public String apmExcelHandle(@RequestBody String pageValue) {
JSONObject parsePageValue = JSON.parseObject(pageValue);
String file = parsePageValue.getString("file");
String name = FilenameUtils.getName(file);
String fileName = Paths.get(System.getProperty("user.dir"), "static", "excel", name).toString();
//
return pageValue;
}
"receiver": "/report/apm/excel/upload", 是具体调用后端上传文件的接口
@SneakyThrows
@ResponseBody
@RequestMapping("/apm/excel/upload")
public String apmExcelUpload(MultipartFile file, HttpServletRequest request) {
String path = Paths.get(System.getProperty("user.dir"), "static", "excel").toString();
File folder = new File(path);
if (!folder.exists()) {
folder.mkdirs();
}
String name = file.getOriginalFilename();
file.transferTo(new File(folder, name));
Map<String, String> data = new HashMap<>(1);
data.put("value", "/excel/" + name);
@SuppressWarnings("serial")
Map<String, Object> rtn = new HashMap<>(3) {
{
put("status", 0);
put("msg", "ok");
put("data", data);
}
};
return JSON.toJSONString(rtn);
}
2725

被折叠的 条评论
为什么被折叠?



