Spring Boot集成Tinymce富文本编辑器

2023-10-12 13:20

本文主要是介绍Spring Boot集成Tinymce富文本编辑器,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

    • 实战:

  • 官网地址:
    http://tinymce.ax-z.cn/general/upload-images.php
  • springboot的demo
    https://blog.csdn.net/haha_201510/article/details/107110473?%3E

实战:

引入:

<script src="${request.contextPath}/statics/plugins/tinymce/js/tinymce/jquery.tinymce.min.js"></script>
<script src="${request.contextPath}/statics/plugins/tinymce/js/tinymce/tinymce.min.js"></script>
<script src="${request.contextPath}/statics/plugins/tinymce/js/tinymce/icons/default/icons.min.js"></script>
tinymce.init({selector: '#recomEvaluationBox',//绑定渲染区height: 300,plugins: 'paste importcss code table advlist fullscreen imagetools  textcolor colorpicker hr  autolink link image lists preview media wordcount',toolbar: 'styleselect |  formatselect | fontsizeselect | forecolor backcolor | bold italic underline strikethrough | image  media | table | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | preview removeformat  hr | paste code  link | undo redo | fullscreen',skin: 'oxide',language: 'zh_CN',//汉化convert_urls: false,// relative_urls : true,images_upload_url: baseURL + "sys/oss/upload",//图片上传地址images_upload_credentials: true,image_dimensions: false,image_class_list: [{title: '无', value: ''},{title: '预览', value: 'preview'},],// images_upload_base_path: '/',forced_root_block: 'p',force_p_newlines: true,importcss_append: true,content_style: `*                         { padding:0; margin:0; }html, body                { height:100%; }img                       { max-width:100%; display:block;height:auto; }a                         { text-decoration: none; }iframe                    { width: 100%; }p                         { line-height:1.6; margin: 0px; }table                     { word-wrap:break-word; word-break:break-all; max-width:100%; border:none; border-color:#999; }.mce-object-iframe        { width:100%; box-sizing:border-box; margin:0; padding:0; }ul,ol                     { list-style-position:inside; }`,insert_button_items: 'image link | inserttable',// CONFIG: Pastepaste_retain_style_properties: 'all',paste_word_valid_elements: '*[*]',        // word需要它paste_data_images: true,                  // 粘贴的同时能把内容里的图片自动上传paste_convert_word_fake_lists: false,     // 插入word文档需要该属性paste_webkit_styles: 'all',paste_merge_formats: true,nonbreaking_force_tab: false,paste_auto_cleanup_on_paste: false,// CONFIG: Fontfontsize_formats: '10px 11px 12px 14px 16px 18px 20px 24px',resize: 'both',// CONFIG: StyleSelectstyle_formats: [{title: '首行缩进',block: 'p',styles: {'text-indent': '2em'}},{title: '行高',items: [{title: '1', styles: {'line-height': '1'}, inline: 'span'},{title: '1.5', styles: {'line-height': '1.5'}, inline: 'span'},{title: '2', styles: {'line-height': '2'}, inline: 'span'},{title: '2.5', styles: {'line-height': '2.5'}, inline: 'span'},{title: '3', styles: {'line-height': '3'}, inline: 'span'}]}],// Tabtabfocus_elements: ':prev,:next',object_resizing: true,// Imageimagetools_toolbar: 'rotateleft rotateright | flipv fliph | editimage imageoptions',file_picker_types: 'media',media_live_embeds: true,//be used to add custom file picker to those dialogs that have it.images_upload_handler: function (blobInfo, success, failure) {var xhr, formData;xhr = new XMLHttpRequest();xhr.withCredentials = false;xhr.open('POST', baseURL + "sys/oss/upload");xhr.onload = function () {var json;if (xhr.status != 200) {failure('HTTP Error: ' + xhr.status);return;}console.log(xhr.responseText);json = JSON.parse(xhr.responseText);json.location = json.url;if (!json || typeof json.location != 'string') {failure('Invalid JSON: ' + xhr.responseText);return;}success(json.location);};formData = new FormData();formData.append('file', blobInfo.blob(), blobInfo.filename());xhr.send(formData);}});
  <div class="form-group"><div class="col-sm-2 control-label">推荐语</div><div class="col-sm-10"><textarea name="" id="recomEvaluationBox" cols="1000" style="width: 150%" rows="10" v-model="recomEvaluation.content"></textarea></div></div>

后端上传代码逻辑:(使用的oss)

	/*** 上传文件*/@RequestMapping("/upload")@RequiresPermissions("sys:oss:all")public R upload(@RequestParam("file") MultipartFile file) throws Exception {if (file.isEmpty()) {throw new RRException("上传文件不能为空");}//上传文件String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));String url = OSSFactory.build().uploadSuffix(file.getBytes(), suffix);//保存文件信息SysOssEntity ossEntity = new SysOssEntity();ossEntity.setUrl(url);ossEntity.setCreateDate(new Date());sysOssService.save(ossEntity);return R.ok().put("url", url);}
  • 效果:
    在这里插入图片描述
    在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

也支持,复制粘贴自动上传图片。

总结:
1.引入js
2:关键的是 init的参数,和上传图片的的回调函数的写法
3:学会使用缩放来切换上传图


这篇关于Spring Boot集成Tinymce富文本编辑器的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/196129

相关文章

Java实现字节字符转bcd编码

《Java实现字节字符转bcd编码》BCD是一种将十进制数字编码为二进制的表示方式,常用于数字显示和存储,本文将介绍如何在Java中实现字节字符转BCD码的过程,需要的小伙伴可以了解下... 目录前言BCD码是什么Java实现字节转bcd编码方法补充总结前言BCD码(Binary-Coded Decima

SpringBoot全局域名替换的实现

《SpringBoot全局域名替换的实现》本文主要介绍了SpringBoot全局域名替换的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录 项目结构⚙️ 配置文件application.yml️ 配置类AppProperties.Ja

Java使用Javassist动态生成HelloWorld类

《Java使用Javassist动态生成HelloWorld类》Javassist是一个非常强大的字节码操作和定义库,它允许开发者在运行时创建新的类或者修改现有的类,本文将简单介绍如何使用Javass... 目录1. Javassist简介2. 环境准备3. 动态生成HelloWorld类3.1 创建CtC

JavaScript中的高级调试方法全攻略指南

《JavaScript中的高级调试方法全攻略指南》什么是高级JavaScript调试技巧,它比console.log有何优势,如何使用断点调试定位问题,通过本文,我们将深入解答这些问题,带您从理论到实... 目录观点与案例结合观点1观点2观点3观点4观点5高级调试技巧详解实战案例断点调试:定位变量错误性能分

Java实现将HTML文件与字符串转换为图片

《Java实现将HTML文件与字符串转换为图片》在Java开发中,我们经常会遇到将HTML内容转换为图片的需求,本文小编就来和大家详细讲讲如何使用FreeSpire.DocforJava库来实现这一功... 目录前言核心实现:html 转图片完整代码场景 1:转换本地 HTML 文件为图片场景 2:转换 H

Java使用jar命令配置服务器端口的完整指南

《Java使用jar命令配置服务器端口的完整指南》本文将详细介绍如何使用java-jar命令启动应用,并重点讲解如何配置服务器端口,同时提供一个实用的Web工具来简化这一过程,希望对大家有所帮助... 目录1. Java Jar文件简介1.1 什么是Jar文件1.2 创建可执行Jar文件2. 使用java

SpringBoot实现不同接口指定上传文件大小的具体步骤

《SpringBoot实现不同接口指定上传文件大小的具体步骤》:本文主要介绍在SpringBoot中通过自定义注解、AOP拦截和配置文件实现不同接口上传文件大小限制的方法,强调需设置全局阈值远大于... 目录一  springboot实现不同接口指定文件大小1.1 思路说明1.2 工程启动说明二 具体实施2

Java实现在Word文档中添加文本水印和图片水印的操作指南

《Java实现在Word文档中添加文本水印和图片水印的操作指南》在当今数字时代,文档的自动化处理与安全防护变得尤为重要,无论是为了保护版权、推广品牌,还是为了在文档中加入特定的标识,为Word文档添加... 目录引言Spire.Doc for Java:高效Word文档处理的利器代码实战:使用Java为Wo

SpringBoot日志级别与日志分组详解

《SpringBoot日志级别与日志分组详解》文章介绍了日志级别(ALL至OFF)及其作用,说明SpringBoot默认日志级别为INFO,可通过application.properties调整全局或... 目录日志级别1、级别内容2、调整日志级别调整默认日志级别调整指定类的日志级别项目开发过程中,利用日志

Java中的抽象类与abstract 关键字使用详解

《Java中的抽象类与abstract关键字使用详解》:本文主要介绍Java中的抽象类与abstract关键字使用详解,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧... 目录一、抽象类的概念二、使用 abstract2.1 修饰类 => 抽象类2.2 修饰方法 => 抽象方法,没有