##楔子
使用
editor.md
图片上传成功后没回显图片URL
,最终发现是返回json 中success 类型导致
##使用记录
上面的图片记录了图片
URL
出现没没出现的 2中情况。下面代码给出解释。最主要的问题是/*resultJs.put("success", "1");此处不要写 字符串的"1",只是写为数字不要带引号*/
@ResponseBody
@RequestMapping("/blog/upFile")
public JSON articleUpFile(HttpServletRequest req, @RequestParam("editormd-image-file") MultipartFile picpaths) {
String url = "blog/" + SysUtils.getDateStr() + "/";
File file = new File(SysConstant.UP_FILE, url);
if (!file.exists() && file.mkdirs()) {
}
JSONObject resultJs=new JSONObject();
String upPicFileName = SysUtils.getUpPicFileName();
file = new File(file, upPicFileName);
url = url + upPicFileName;
try {
picpaths.transferTo(file);
/*resultJs.put("success", "1");此处不要写 字符串的"1",只是写为数字不要带引号*/
resultJs.put("success", 1);
resultJs.put("message", "上传成功");
resultJs.put("url",SysConstant.PICURL + url);
} catch (IllegalStateException | IOException e) {
resultJs.put("success", 0);
resultJs.put("message", "上传失败");
}
return resultJs;
}
##图片上传后台接收为何是editormd-image-file
从上图中可以看出,editor工具构造的file字段是editormd-image-file
。
总有人问,为啥上传不会回显 ,这个里面有个 Demo,可以参考,https://blog.csdn.net/u012848709/article/details/103290253