SpringMVC 使用百度Ueditor

碰到的问题:

1. ueditor 未找到上传数据,如果使用Spring MVC 请使用下面的JAR。源代码地址:https://gitee.com/milin/springmvc-ueditor


使用方式

1. 新建Spring  Controller类

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.baidu.ueditor.ActionEnter;


@Controller
@RequestMapping("/ueditor")
public class UeditorController {
	private Logger log = LoggerFactory.getLogger(getClass());

	@RequestMapping(value = "/config")
	public void config(HttpServletRequest request, HttpServletResponse response) {

		response.setContentType("application/json");
		String rootPath = request.getSession().getServletContext().getRealPath("/");
		try {
			String config = this.getClass().getResource("/").getPath() + "config/config.json";
			String exec = new ActionEnter(request, rootPath, config).exec();
			PrintWriter writer = response.getWriter();
			writer.write(exec);
			writer.flush();
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

说明:

ActionEnter(request, rootPath, config)

这个方法接受三个参数,

第一个request 对象,

第二个 rootPath  指定文件保存的根目录,会跟配置文件中的imagePathFormat 拼接到一起组成文件保存的绝对路径

第三个configName 指定配置文件的绝对路径


2. config.json 配置文件可以放到项目中任意位置(使用绝对路径访问的)

3. 修改 ueditor.config.js 中 serverUrl 的路径为配置的controller 即可




jar包使用方式:



<dependency>
			<groupId>cn.songxinqiang</groupId>
			<artifactId>com.baidu.ueditor</artifactId>
			<version>1.1.2-edit-1.4</version>
			<scope>system</scope>
			<systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/ueditor-1.1.4.jar</systemPath>
		</dependency>

GroupId 和 artifactId  ,version  可以任意填写

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值