Kind Editor 编辑器 图片上传

KindEditor 编辑器 图片上传

最近接触到了html文本的存储。 以前没有涉及这么全面的html + 图片 上传。

今天用KindEditor 做了一些功能。 我的项目用spring mvc+mybatis 整的。


贴出我的前端和后端代码 。供新手参考。 不用多余jar。 跟普通上传图片差不多。


前端js代码

var editor;
		KindEditor.ready(function(K) {
			var editor = K.create('textarea[name="Description"]', {
				uploadJson : 'kingedit/imageUpload',上传图片的地址
			});
			
			
		});

前端html代码

<textarea rows="5" cols="70" name="Description"></textarea>
		   		


后端上传图片代码,注意,编辑器必须接收到返回的json。

@RequestMapping("/imageUpload")
	@ResponseBody
	public String imageUpload(MultipartHttpServletRequest request) throws Exception {
		String webpath =  null;
		try {
			//上传图片
			MultipartFile file = request.getFile("imgFile");
			webpath = FileUtil.saveWebImgFile(file);
			if(StringUtils.isNotEmpty(webpath)){
				String path = request.getContextPath();
				String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
				webpath = "{\"error\" : 0,\"url\" : \""+basePath+webpath+"\"}";//成功
			}else{
				webpath = "{\"error\" : 0,\"message\" : \"上传文件不存在\"}";//失败
			}
		}catch (Exception e) {
			e.printStackTrace();
		}
		return webpath;
	}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值