1. 程式人生 > >editor.md使用——圖片上傳沒回顯url

editor.md使用——圖片上傳沒回顯url

楔子

使用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