若依微服务框架,富文本加入图片保存时出现JSON parse error: Unexpected character (‘/‘ (code 47)):...

若依微服务框架,富文本加入图片保存时出现JSON parse error: Unexpected character

一、问题

若依微服务项目在使用富文本框的时候,富文本加入图片进行保存的时候会出现以下错误

JSON parse error: Unexpected character ('/' (code 47)): maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser); nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character ('/' (code 47)): maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser) at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 1, column: 152]

针对这个问题,目前有两种解决方案

二、解决

1.修改网关配置

若依官方问题解决:https://doc.ruoyi.vip/ruoyi-cloud/other/faq.html#特殊字符串被过滤的解决办法

若依的微服务使用了nacos

1.打开nacos,找到ruoyi-gateway-dev.yml配置文件,

2.然后找到security.xss.excludeUrls然后再后面加入调用的接口,进行排除
方法直接了当,不过不怎么安全,因为这本来就是防止xss攻击的,这里给接口放开了

2、对数据进行加密解密

vue对上传的富文本数据进行加密操作,后台进行解密操作(使用中)

2.1安装插件

因为若依后台带有best64工具类,前端这里直接安装

bash 复制代码
npm install --save js-base64

2.2vue页面加密使用

bash 复制代码
// 加密
Base64.encode(data);
// 解密
Base64.decode(data);

2.3后台解密存储

若依Base64工具类在safety-common-core模块下
Ruoyi-Cloud\ruoyi-common\ruoyi-common-core\src\main\java\com\ruoyi\common\core\utils\sign

我这里只把富文本数据进行加密了,后台解密如下

bash 复制代码
// str 解密后的数据
// data 前台传来的加密数据
String str = new String(Base64.decode(data));

这样就直接完成了。

相关推荐
木头没有瓜7 分钟前
idea离线安装插件
java·ide·intellij-idea
llwszx17 分钟前
Spring中DelayQueue深度解析:从原理到实战(附结构图解析)
java·后端·spring·delayqueue·延迟任务
述雾学java31 分钟前
Spring Cloud Feign 整合 Sentinel 实现服务降级与熔断保护
java·spring cloud·sentinel
保持学习ing32 分钟前
苍穹外卖day3--公共字段填充+新增菜品
java·阿里云·实战·springboot·前后端·外卖项目·阿里云文件存储
77qqqiqi1 小时前
正则表达式
java·后端·正则表达式
厦门德仔1 小时前
【WPF】WPF(样式)
android·java·wpf
大春儿的试验田1 小时前
高并发收藏功能设计:Redis异步同步与定时补偿机制详解
java·数据库·redis·学习·缓存
Gappsong8741 小时前
【Linux学习】Linux安装并配置Redis
java·linux·运维·网络安全
hqxstudying1 小时前
Redis为什么是单线程
java·redis
RainbowSea2 小时前
NVM 切换 Node 版本工具的超详细安装说明
java·前端