wangEditor使用教程

news/2024/10/23 7:32:13/

1、官网地址

https://www.wangeditor.com/

2、页面引入js

<script th:src="@{/js/wangEditor4.7.6.js}"></script>

3、代码

<div id="inspectionContents"></div>

 4、js代码

        const E = window.wangEditorconst editor1 = new E('#inspectionContents');editor1.config.showLinkImg = false//图片上传,后端接口editor1.config.uploadImgServer=prefix+'/uploadImg'editor1.config.debug=true;editor1.config.uploadFileName = 'file'editor1.create();

5、后端代码

    @RequestMapping("/uploadImg")@ResponseBodypublic String uploadImg(MultipartFile file, HttpServletRequest request)throws Exception{return dailyInspectionService.uploadImg(file, request);}
    @Overridepublic String uploadImg(MultipartFile file, HttpServletRequest request) {//协议名 http // httpsString scheme = request.getScheme();//域名String serverName = request.getServerName();//项目名String contextPath = request.getContextPath();//路径String url=scheme+"://"+serverName+":"+port+contextPath;//文件名String filename = file.getOriginalFilename();try {saveImg(file.getInputStream(),filename);}catch (Exception e){throw new RuntimeException("图片上传失败");}JSONObject object=new JSONObject();List<ReturnData> list=new ArrayList<>();ReturnData data=new ReturnData();data.setUrl(url+"/file/"+filename);data.setAlt("图片");list.add(data);object.put("errno","0");object.put("data",list.toArray());return object.toJSONString();}
    /*** 图片处理** @param stream* @param filename* @throws Exception*/private void saveImg(InputStream stream, String filename)throws Exception{String                 path=this.getClass().getClassLoader().getResource("").getPath()+"/static/file/";File file=new File(path);String str=file.getPath()+File.separator+filename;FileOutputStream fs=new FileOutputStream(str);byte[] buffer =new byte[1024*1024];int bytesum = 0;int byteread = 0;while ((byteread=stream.read(buffer))!=-1) {bytesum+=byteread;fs.write(buffer,0,byteread);fs.flush();}fs.close();stream.close();}

6、图片上传对应的后端接口返回类型,wangEditor官网有详细的说明。以上方法是将图片上传到target/static/file/路径下。


http://www.ppmy.cn/news/651685.html

相关文章

wangEditor系列之工具栏配置

文章の目录 一、查看工具栏的默认配置二、查询编辑器注册的所有菜单 key &#xff08;可能有的不在工具栏上&#xff09;三、重新配置工具栏&#xff0c;显示哪些菜单&#xff0c;以及菜单的排序、分组四、在当前 toolbarKeys 的基础上继续插入新菜单&#xff0c;如自定义扩展的…

wangeditor富文本编辑器的使用

官方文档: http://www.wangeditor.com/ 1. 引入编辑器 npm install wangeditor 2. 使用编辑器 (1) 创建容器 <div id"wangeditor"><div ref"editorElem"></div> </div>(2) 创建并且实例化组件 vue的使用方法 //vue的使用 im…

Vue3 富文本编辑器插件wangEditor

先上Demo 最近笔者在Vue3开发过程中需要使用到富文本编辑器&#xff0c;最后找到这个插件&#xff0c;觉得挺不错&#xff0c;如果有开发者也有这样的需求&#xff0c;可以试试 先上demo: Vue3使用方法 安装 yarn add wangeditor/editor # 或者 npm install wangeditor/edi…

wangEditor的完整使用(二)

上一篇博客讲了wangEditor的使用&#xff0c;但是有一个问题就是在富文 本编辑器里编辑时不能看到文章的预览效果。 下面我来讲解下如何实现在编辑时也可以看到预览效果。 设置一个按钮 <div class"layui-inline layui-show-xs-block"><button type&quo…

wangEditor 富文本编辑器使用

wangEditor 富文本编辑器使用 框架&#xff1a; react hooks 链接: 官方文档参考 富文本编辑器组件 import wangeditor/editor/dist/css/style.css; // 引入 css import { useState, useEffect } from react; import { Editor, Toolbar } from wangeditor/editor-for-react;…

vue 中使用 wangeditor

项目中用到了富文本&#xff0c;选来选去选择了wangeditor,先写了demo&#xff0c;用起来还算比较简单 用法 安装 npm install wangeditor/editor --save npm install wangeditor/editor-for-vue --save 空白编辑器 <template><div id"app"><div…

wangEditor的使用及上传图片(一)

由于业务需要&#xff0c;最近新入手了一款富文本编辑器wangEditor&#xff0c;这是一款轻量级的富文本编辑器&#xff0c;比起百度的ueditor&#xff0c;这款编辑器的界面更加简单&#xff0c;文档也很详细。对于需求不是很高的功能来说&#xff0c;这款编辑器实在是不二之选。…

wangEditor的完整使用(一)

最近在做一个类似博客之类的页面&#xff0c;所以就打算借助wangEditor这一富文本编辑器来实现项目的需求。主要使用SpringBootJSPLayUi来完成。一.导入wangEditor.js 我自己使用的是wangEditor.min.js,通过手工导入的方式放在项目的静态文件下来引用。 下载地址&#xff1a;…