百度富文本和springboot集成
2017-06-26 00:00
141 查看
摘要: 随手小计
1.先说一下百度富文本的原理,理解了原理,接下来就好搞 了,初始化加载百度富文本编辑器的时候,会发送一个统一请求,然后读取config.josn后返回里面的数据。
2.上传就是根据config.json里面配置的各种url来上传了,
1.先说一下百度富文本的原理,理解了原理,接下来就好搞 了,初始化加载百度富文本编辑器的时候,会发送一个统一请求,然后读取config.josn后返回里面的数据。
2.上传就是根据config.json里面配置的各种url来上传了,
/** * ClassName:UeditorController Function: TODO ADD FUNCTION. Reason: TODO ADD * REASON. Date: 2017年2月25日 上午11:12:20 * * @author likaixuan * @version V1.0 * @since JDK 1.7 * @see */ @RequestMapping("/ueditor") @Controller public class UeditorController { @Value("${upload.image}") private String savePath; @Value("${hikpedia.image.url}") private String preUrl; @RequestMapping(value="/upload",method=RequestMethod.GET) @ResponseBody public void config(HttpServletRequest request,HttpServletResponse response) throws IOException { String actionName = request.getParameter("action"); if ("config".equals(actionName)) { InputStream in = new FileInputStream(UeditorController.class.getResource("/").getPath() + "config.json"); OutputStream out = response.getOutputStream(); IOUtils.copy(in, out); } } @RequestMapping(value="/upload",method=RequestMethod.POST) @ResponseBody public Map<String,String> upload(HttpServletRequest request, HttpServletResponse response,MultipartFile upfile) throws UnsupportedEncodingException{ Map<String, String> result = new HashMap<String, String>(); String url = FileUploadUtil.singleFileUpload(upfile, savePath, preUrl); String state = "SUCCESS"; // 返回json的对象 result.put("url", url); result.put("size", String.valueOf(upfile.getSize())); result.put("type", upfile.getContentType()); result.put("title", upfile.getOriginalFilename()); result.put("original", upfile.getName()); result.put("name", upfile.getOriginalFilename()); result.put("state", state); return result; } }
import java.io.File; import java.io.IOException; import org.springframework.web.multipart.MultipartFile; /** * ClassName:FileUploadUtil Function: TODO ADD FUNCTION. Reason: TODO ADD * REASON. Date: 2017年3月2日 下午7:37:12 * * @author likaixuan * @version V1.0 * @since JDK 1.7 * @see */ public class FileUploadUtil { private static final String SEPARATOR = "/"; /** * singleFileUpload:(单个文件上传) * TODO(返回文件上传后所在路径) * * @return fileurl * @since JDK 1.7 */ public static String singleFileUpload(MultipartFile file,String savePath,String prePath) { String filePath = "";// 文件上传后,可访问的路径 try { //判断savePath路径最后是否带/,如果不带追加 String lastStr = savePath.substring(savePath.length()-2); if(lastStr.contains("/")){ filePath = savePath + DateUtil.getNowYearMoth() + SEPARATOR + file.getOriginalFilename(); }else{ savePath+=SEPARATOR; filePath = savePath +SEPARATOR+ DateUtil.getNowYearMoth() + SEPARATOR + file.getOriginalFilename(); } // 前端传入mulFileSource // 创建压缩前源文件 File fileSourcePath = new File(savePath + DateUtil.getNowYearMoth()); File fileSource = new File(fileSourcePath, file.getOriginalFilename()); if (!fileSourcePath.exists()) { fileSourcePath.mkdirs(); } file.transferTo(fileSource); } catch (IllegalStateException e) { throw new RuntimeException(); } catch (IOException e) { throw new RuntimeException(); } /*return savePath+ DateUtil.getNowYearMoth() + SEPARATOR + file.getOriginalFilename();*/ return prePath+SEPARATOR+DateUtil.getNowYearMoth()+SEPARATOR+file.getOriginalFilename(); } }
相关文章推荐
- 百度搜索引擎中文分词与文本粒度
- 百度富文本 uEditor 调用不到,解决办法
- 百度富文本的使用
- asp.net集成百度ueditor富文本,在后台获取ueditor修改后的数据
- WPF 自制文本下拉框,类似在百度中输出关键字,会弹出一些选项
- 百度富文本编辑框的使用
- 百度ueditor富文本--自定义插件按钮
- [软件资讯]百度发布富文本开源编辑器UEditor
- 百度富文本ueditor使用 以及 与 Struts2 整合时出现的问题解决
- 文本分析--停用词集合(结合哈工大停用词表、四川大学机器智能实验室停用词库、百度停用词表等)
- React中使用UEditor百度富文本的方法
- 记录百度富文本编辑框 UEditor 的一个问题
- 百度富文本web编辑器UEditor上传处理部分的改造
- 百度ueditor富文本--图片保存路径的配置以及上传到远程服务器
- 搜:搜索内容,返回百度的结果 20140801 ①文本处理
- powershell 使用百度AI进行文本识别
- 发现个好用的富文本空间百度UEditor
- 百度富文本ueditor和umeditor遇到的问题和解决办法
- 百度的UEditor富文本控件的使用
- 百度富文本在vue项目中的使用