wangEditor富文本wangEditor-3.0.7

 <script type="text/javascript" src="${ctx }/static/js/wangEditor.min.js"></script>

var E = window.wangEditor
var editor = new E('#editor')
// 配置服务器端地址
editor.customConfig.uploadImgServer = '/upload'
editor.customConfig.withCredentials = true
editor.customConfig.uploadFileName = 'files'
editor.customConfig.uploadImgHeaders = {
}
editor.customConfig.uploadImgParams = {
}
editor.customConfig.uploadImgHooks = {
   before: function (xhr, editor, files) {
    console.info(editor);
   },
   success: function (xhr, editor, result) {
       // 图片上传并返回结果,图片插入成功之后触发
       // xhr 是 XMLHttpRequst 对象,editor 是编辑器对象,result 是服务器端返回的结果
   },
   fail: function (xhr, editor, result) {
   },
   error: function (xhr, editor) {
   },
   timeout: function (xhr, editor) {
   },
   customInsert: function (insertImg, result, editor) {
       var url = result
       insertImg(url)
   }
}
editor.create()
editor.txt.html('${article.content}')


html代码

   <div id="editor">
    
         </div>


得到富文本内容

editor.txt.html()



图片上传代码

@RequestMapping(value = "/upload", method = RequestMethod.POST)
@ResponseBody
public String uploadFile(MultipartHttpServletRequest multipartRequest,HttpServletResponse response) throws Exception {
String fileId = "";
String extName = "";
// 获得文件:
MultipartFile file = multipartRequest.getFile("files");
// 获得文件名:
String filename = file.getOriginalFilename();


if (filename.endsWith(".jsp") || filename.endsWith(".php") || filename.endsWith(".asp") || filename.endsWith(".aspx") || filename.endsWith(".js")) {
return "error";
} else {
// 获得输入流:
InputStream input = file.getInputStream();
extName = filename.substring(filename.lastIndexOf(".") + 1);
fileId = this.operationService.storeFile(input, extName);
}
response.setHeader("Access-Control-Allow-Origin", "*");
return fileId + "." + extName;
}


private static final String ORIGINAL_PATH = "ori";


public String storeFile(InputStream inputStream, String extName) throws Exception {
String picId = DateUtil.getDateString(new Date(), "yyyyMMddHHmmss") + ObjectId.get();
String filePath = "";
if (ImageUtil.isImage(extName)) {
filePath = imageDir + "/" + ORIGINAL_PATH + "/" + picId + "." + extName;
} else {
filePath = fileDir + "/" + picId + "." + extName;
}
FileUtil.InputStreamTOFile(inputStream, filePath);
return picId;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值