5 Star 13 Fork 5

阿信sxq / UeditorJavaLib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
使用示例.md 1.75 KB
一键复制 编辑 原始数据 按行查看 历史
阿信sxq 提交于 2017-02-19 22:41 . 添加使用示例

使用示例

下面演示在spring mvc的环境下使用修改版的方法,maven项目为例

maven依赖配置

修改版本(以及未修改代码版本)均上传到maven中央仓库

修改版的坐标

    <dependency>
        <groupId>cn.songxinqiang</groupId>
        <artifactId>com.baidu.ueditor</artifactId>
        <version>1.1.2-edit-1.0</version>
    </dependency>

未修改版,只需将版本号修改为1.1.2-offical

配置文件

官方给出的配置文件,放到src/main/resources里面,文件名为ueditor.config.json,内容和管饭过得无其他不一样

启动入口

创建控制器作为专门的入口控制器,实现ServletContextAware接口,以实现对项目根路径的获取

关键的是入口方法

@Controller
@RequestMapping("/ued")
public class UeditorController implements ServletContextAware {
    private String rootPath;

    @RequestMapping("/ueditor")
    @ResponseBody
    public String ueditorConfig(HttpServletRequest request, HttpServletResponse response) {
        return new ActionEnter(request, rootPath, UeditorController.class.getClassLoader()
            .getResource("ueditor.config.json").getPath()).exec();

    }
    
    @Override
    public void setServletContext(ServletContext servletContext) {
        rootPath = servletContext.getRealPath("/");
    }
}

其中UeditorController.class.getClassLoader().getResource("ueditor.config.json").getPath()是获取配置文件的具体路径, 可能需要根据实际进行修改

前端编辑器配置

使用上面的入口,在前端的配置需要修改配置文件ueditor.config.js的入口为如下内容

    // 服务器统一请求接口路径
    , serverUrl: content + "/ued/ueditor"
Java
1
https://gitee.com/songxinqiang/UeditorJavaLib.git
git@gitee.com:songxinqiang/UeditorJavaLib.git
songxinqiang
UeditorJavaLib
UeditorJavaLib
master

搜索帮助