主题: 求解:springmvc+4.17上传本地图片问题 |
作者: 问题, 发布日期: 2013-06-26 10:02:37, 浏览数: 5515 |
控制器:
@RequestMapping(value = "/upload") 页面:
<link rel="stylesheet" href="${rc.contextPath }/summary_static/kindeditor-4.1.7/themes/default/default.css" />
{ error : '0' ,url:'C://attached/image/20130626/20130626095909_432.jpg'} 没有把图片在editor里边显示 求解,谢谢。 |
作者: Roddy, 发布日期: 2013-06-26 14:23:45 |
转到疑问解答。
|
回复 |
作者: EditorPlus, 发布日期: 2013-07-06 10:50:23 |
@RequestMapping(method=RequestMethod.POST) public void post(@RequestParam(value="dir",defaultValue="file")String dir,HttpServletResponse response,MultipartRequest multipartRequest)throws Exception { Iterator<String> names = multipartRequest.getFileNames(); boolean hasFile = false; while (names != null && names.hasNext()) { hasFile = true; String name = names.next(); MultipartFile mFile = multipartRequest.getFile(name); this.attachmentService.saveAttachment(mFile, dir, "").toResponse(response); logger.debug("UPLOAD File [" + mFile.getOriginalFilename() + "][" + mFile.getSize() + "]"); } if (hasFile == false) { AttMessageDTO.Error("至少选择一个文件上传").toResponse(response); } } /** * */ package net.fytech.dls.infrastructure.ctrls.attachment; import java.io.Writer; import javax.servlet.http.HttpServletResponse; /** * @author 2013-6-15 * */ public class AttMessageDTO implements java.io.Serializable { /** * */ private static final long serialVersionUID = 1L; private int error = 0; private String message = ""; private String url = ""; public static AttMessageDTO Error(String message) { AttMessageDTO dto = new AttMessageDTO(""); dto.error = 1; dto.message = message; return dto; } public static AttMessageDTO Success(String url) { AttMessageDTO dto = new AttMessageDTO(url); return dto; } public AttMessageDTO() { } public AttMessageDTO(String url) { this.url = url; } public int getError() { return error; } public void setError(int error) { this.error = error; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public void toResponse(HttpServletResponse response) throws Exception{ response.setContentType("text/html"); Writer out = response.getWriter(); out.append("{\"error\":" + this.error + ", \"url\": \"" + url + "\"}"); } } KindEditor在文件上传成功返回时无法获取JSON,只能用字符串输出到Response中,希望以后版本能修复这个问题 |
回复 |