springboot请求json内容不能含有富文本编辑器获取的html代码

问题
当我使用富文本编辑器nicEditor获取内容 存入json 上传到spring boot的后端的时候, 我发现我并不能获取html格式的代码

解决方案
当上传的时候我们使用htmlencode编码处理

function htmlencode(html) {
         var temp = document.createElement ("div");
         //2.然后将要转换的字符串设置为这个元素的innerText(ie支持)或者textContent(火狐,google支持)
         (temp.textContent != undefined ) ? (temp.textContent = html) : (temp.innerText = html);
         //3.最后返回这个元素的innerHTML,即得到经过HTML编码转换的字符串了
         var output = temp.innerHTML;
         temp = null;
         return output;
}

当我们在展示的从后端获取的时候 htmldecode 解码处理

    function htmldecode(html) {
//1.首先动态创建一个容器标签元素,如DIV
        var temp = document.createElement("div");
        //2.然后将要转换的字符串设置为这个元素的innerHTML(ie,火狐,google都支持)
        temp.innerHTML = html;
        //3.最后返回这个元素的innerText(ie支持)或者textContent(火狐,google支持),即得到经过HTML解码的字符串了。
        var output = temp.innerText || temp.textContent;
        temp = null;
        return output;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值