@RestController
@RequestMapping("/upload")
public class UploadController {
private final static String FILE_SAVE_PATH = "C:/Users/86182/Desktop/第二个CRM权限管理/OA前台/layuimg";
@RequestMapping("/uploadImg")
private Object uploadFile(@RequestParam(value = "file") MultipartFile file, HttpServletRequest request) {
Map<String,Object> mv=new HashMap<String, Object>();
Map<String, String> mvv = new HashMap<String, String>();
if(file==null) {
return new Result("200", "上传失败", 500, false);
}
String fileName = file.getOriginalFilename();
String suffixName = fileName.substring(fileName.lastIndexOf("."));
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
String savePath = FILE_SAVE_PATH + File.separator+uuid + suffixName;
File f = new File(savePath);
if (!f.getParentFile().exists()) {
f.getParentFile().mkdirs();
}
try {
file.transferTo(f);
} catch (IOException e) {
e.printStackTrace();
return new Result("200", "上传失败", 500, false);
}
System.out.println(uuid+suffixName);
mvv.put("src", "layuimg/" + uuid+suffixName);
mvv.put("title",uuid+suffixName);
mv.put("code", 0);
mv.put("msg", "上传成功");
mv.put("data", mvv);
return mv;
}
}
layedit.set({
uploadImage: {
url: globalData.server + '/upload/uploadImg'
}
});
var index = layedit.build('demo', {
tool: ['strong'
, 'italic'
, 'underline'
, 'del'
, '|'
, 'left'
, 'center'
, 'right'
, 'link'
, 'unlink'
, 'face'
, 'image'
, 'help'
]
});