UEditor 编辑器

1:插件的导入

2:工具类

package com.flow.util;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class UEditorContentUtil {

    /**
     * @Title: getExcelsFromContent 
     * @Description: 获取UEditor内容中的Excel文件
     * @param content UEditor内容
     * @param rootPath 系统路径
     * @return
     * @throws Exception
     */
    public static List<File> getExcelsFromContent(String content,
            String rootPath) throws Exception {
        List<File> excelList = new ArrayList<File>();

        Document doc = Jsoup.parse(content);
        // 获取内容中的a标签
        Elements els = doc.getElementsByTag("a");
        Iterator<Element> it = els.iterator();
        for (; it.hasNext();) {
            Element el = it.next();
            // 获取文件地址
            String href = el.attr("href");
            String[] str = href.split("\.");
            String end = str[str.length - 1];
            // 判断是否是Excel文件
            if ("xls".equals(end) || "xlsx".equals(end)) {
                File file = new File(rootPath, href);
                if (file.exists()) {
                    excelList.add(file);
                }
            }
        }

        return excelList;
    }
}

3:页面书写

  1):js引用

<script type="text/javascript" src="plugins/ueditor1_4_3_2/ueditor.config.js"></script>
<script type="text/javascript" src="plugins/ueditor1_4_3_2/ueditor.all.js"> </script>
<script type="text/javascript" src="plugins/ueditor1_4_3_2/lang/zh-cn/zh-cn.js"></script>

  2):JQ

  var ue = UE.getEditor('editor');//"editor"对应  ---3)的id属性 <script id="editor"></script>

  ue.hasContents();//判断插件是否有内容(文字或附件等)

  ue.getContent();//主要存放上传的文件地址(后台使用)

  ue.getContentTxt();//附件名+文字内容(后台使用)

  3):放入到页面

<td class="tl xwid">
   <script id="editor" type="text/plain" style="100%;height:210px;"></script>
</td>

  4):文件地址可在(config.json)文件中调节,也可使用默认地址

  如文件地址默认为:

  

  

原文地址:https://www.cnblogs.com/ai211234/p/5945205.html