使用ueditor编写文章

使用ueditor编写文章

UEditor是由百度WEB前端研发部开发的所见即所得的开源富文本编辑器,具有轻量、可定制、用户体验优秀等特点。开源基于BSD协议,所有源代码在协议允许范围内可自由修改和使用。百度UEditor的推出,可以帮助不少网站开发者在开发富文本编辑器所遇到的难题,节约开发者因开发富文本编辑器所需要的大量时间,有效降低了企业的开发成本。

ueditorgithub官网

关于下载:
为了方便起见,可直接点击我的网盘链接下载。
网盘链接

使用:

  1. 将ueditor里面的文件全部移动到你的java项目里。
    在这里插入图片描述

  2. 将下面的所有文件都放入static目录下(注意,为了方便,请直接放到static下面,要新建任何文件夹来存储)

  3. 编写UEditorController

package com.example.demo;

import com.example.demo.domain.Board;
import com.example.demo.service.imp.BoardServiceImp;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.example.demo.ueditor.*;


/**
 * @ClassName UEditorController
 * @Description TODO
 * @Auther ydc
 * @Date 2019/1/26 17:24
 * @Version 1.0
 **/
@RestController
public class UEditorController  {


    private BoardServiceImp boardServiceImp;

    @Autowired
    public void setBoardServiceImp(BoardServiceImp boardServiceImp) {
        this.boardServiceImp = boardServiceImp;
    }

    @RequestMapping("userWriting")
    public ModelAndView UEditor(){
        ModelAndView mv = new ModelAndView();
        List<Board> boards=boardServiceImp.findAllBoard();
        mv.addObject("boards",boards);
        mv.setViewName("writing");
        return mv;
    }

    @RequestMapping(value="/config")
    public void config(HttpServletRequest request, HttpServletResponse response) {
        response.setContentType("application/json");
        String rootPath = request.getSession().getServletContext().getRealPath("/");
        try {
            String exec = new ActionEnter(request, rootPath).exec();
            PrintWriter writer = response.getWriter();
            writer.write(exec);
            writer.flush();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

注意这个java文件必须和你的application.java放在同一级目录下(详情可以观察我的项目目录)
最后,将config.json文件拷贝到和.properties同一级目录下,即可使用。
参考博客链接

github

项目演示

猜你喜欢

转载自blog.csdn.net/qq_40774175/article/details/87932913