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 Predicate接口定义详解

《JavaPredicate接口定义详解》Predicate是Java中的一个函数式接口,它代表一个判断逻辑,接收一个输入参数,返回一个布尔值,:本文主要介绍JavaPredicate接口的定义... 目录Java Predicate接口Java lamda表达式 Predicate<T>、BiFuncti

Spring Security基于数据库的ABAC属性权限模型实战开发教程

《SpringSecurity基于数据库的ABAC属性权限模型实战开发教程》:本文主要介绍SpringSecurity基于数据库的ABAC属性权限模型实战开发教程,本文给大家介绍的非常详细,对大... 目录1. 前言2. 权限决策依据RBACABAC综合对比3. 数据库表结构说明4. 实战开始5. MyBA

Spring Security方法级安全控制@PreAuthorize注解的灵活运用小结

《SpringSecurity方法级安全控制@PreAuthorize注解的灵活运用小结》本文将带着大家讲解@PreAuthorize注解的核心原理、SpEL表达式机制,并通过的示例代码演示如... 目录1. 前言2. @PreAuthorize 注解简介3. @PreAuthorize 核心原理解析拦截与

一文详解JavaScript中的fetch方法

《一文详解JavaScript中的fetch方法》fetch函数是一个用于在JavaScript中执行HTTP请求的现代API,它提供了一种更简洁、更强大的方式来处理网络请求,:本文主要介绍Jav... 目录前言什么是 fetch 方法基本语法简单的 GET 请求示例代码解释发送 POST 请求示例代码解释

Java图片压缩三种高效压缩方案详细解析

《Java图片压缩三种高效压缩方案详细解析》图片压缩通常涉及减少图片的尺寸缩放、调整图片的质量(针对JPEG、PNG等)、使用特定的算法来减少图片的数据量等,:本文主要介绍Java图片压缩三种高效... 目录一、基于OpenCV的智能尺寸压缩技术亮点:适用场景:二、JPEG质量参数压缩关键技术:压缩效果对比

Java调用C++动态库超详细步骤讲解(附源码)

《Java调用C++动态库超详细步骤讲解(附源码)》C语言因其高效和接近硬件的特性,时常会被用在性能要求较高或者需要直接操作硬件的场合,:本文主要介绍Java调用C++动态库的相关资料,文中通过代... 目录一、直接调用C++库第一步:动态库生成(vs2017+qt5.12.10)第二步:Java调用C++

springboot+dubbo实现时间轮算法

《springboot+dubbo实现时间轮算法》时间轮是一种高效利用线程资源进行批量化调度的算法,本文主要介绍了springboot+dubbo实现时间轮算法,文中通过示例代码介绍的非常详细,对大家... 目录前言一、参数说明二、具体实现1、HashedwheelTimer2、createWheel3、n

Java利用docx4j+Freemarker生成word文档

《Java利用docx4j+Freemarker生成word文档》这篇文章主要为大家详细介绍了Java如何利用docx4j+Freemarker生成word文档,文中的示例代码讲解详细,感兴趣的小伙伴... 目录技术方案maven依赖创建模板文件实现代码技术方案Java 1.8 + docx4j + Fr

SpringBoot首笔交易慢问题排查与优化方案

《SpringBoot首笔交易慢问题排查与优化方案》在我们的微服务项目中,遇到这样的问题:应用启动后,第一笔交易响应耗时高达4、5秒,而后续请求均能在毫秒级完成,这不仅触发监控告警,也极大影响了用户体... 目录问题背景排查步骤1. 日志分析2. 性能工具定位优化方案:提前预热各种资源1. Flowable

基于SpringBoot+Mybatis实现Mysql分表

《基于SpringBoot+Mybatis实现Mysql分表》这篇文章主要为大家详细介绍了基于SpringBoot+Mybatis实现Mysql分表的相关知识,文中的示例代码讲解详细,感兴趣的小伙伴可... 目录基本思路定义注解创建ThreadLocal创建拦截器业务处理基本思路1.根据创建时间字段按年进