Springmvc整合KindEditor

Springmvc整合KindEditor

OSChina上看到这款工具,界面挺简洁,于是..
132610_O3Wf_819243.png_度娘
132632_II8A_819243.png_官网down
132653_9rTN_819243.png_文件列表
使用

_Js引入:
<script type="text/javascript" src="www/kindeditor/kindeditor-all-min.js"></script>
_html容器:
<textarea name="description" rows="15" cols="50"></textarea>
_初始化容器:

<script type="text/javascript">
           var editor;
           KindEditor.ready(function(K) {
              editor = K.create('textarea[name="description"]', {
                  resizeType : 1,
                  allowPreviewEmoticons : false,
                  allowImageUpload : true,
                  uploadJson : 'action/imageupload',
                  filePostName:'file',
                  items : [
                     'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                     'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
                     'insertunorderedlist', '|', 'emoticons', 'image', 'link']
              });
           }); </script>



_后台@Controller

@RequestMapping(value="/action/imageupload",method=RequestMethod.POST) @ResponseBody
    public String imageProcess(HttpServletRequest req,@RequestParam MultipartFile file) throws IOException{
       if(!file.getContentType().contains("image")){
           return "{\"error\":1,\"message\":\"plase select imageFile~\"}";
       }
       String url=req.getScheme()+"://"+req.getServerName()+":"+req.getServerPort()+req.getContextPath()+"/"+"www/image/upload/";
       String realPath = req.getSession().getServletContext().getRealPath("/www/image/upload");
       String fileName = dateFormat.format(Calendar.getInstance().getTime())+
              "_"+file.getOriginalFilename();
       url+=fileName;
       File downfile = new File(realPath,fileName);
       if(downfile.exists()){
           return "{\"error\":1,\"message\":\"pricture exists~\"}";
       }
       FileUtils.copyInputStreamToFile(file.getInputStream(), downfile);
       return "{\"error\":0,\"url\":\""+url+"\"}";
    }@kindeditor规定返回json格式{error:0|+,url(error(0)):url,message(error+):errorMessage};



_运行效果(上传图片)

132731_HxJW_819243.png

132731_UCly_819243.png

132732_Nkic_819243.png

132732_VAtb_819243.png

132735_UUJ4_819243.png


Over.2014/4/28/13:26.By:DayDayUp

 

 


转载于:https://my.oschina.net/LiveCreator/blog/227447

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值