本文整理汇总了Java中org.springframework.web.multipart.commons.CommonsMultipartResolver.resolveMultipart方法的典型用法代码示例。如果您正苦于以下问题:Java CommonsMultipartResolver.resolveMultipart方法的具体用法?Java CommonsMultipartResolver.resolveMultipart怎么用?Java CommonsMultipartResolver.resolveMultipart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.multipart.commons.CommonsMultipartResolver
的用法示例。
在下文中一共展示了CommonsMultipartResolver.resolveMultipart方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: upload2
import org.springframework.web.multipart.commons.CommonsMultipartResolver; //导入方法依赖的package包/类
/**
* 向当前运行的war中上传文件
* @param upPath
* @param request
* @param response
* @return
* @throws IllegalStateException
* @throws IOException
*/
@RequestMapping("/upload")
public String upload2(HttpServletRequest request, HttpServletResponse response)
throws IllegalStateException, IOException {
// @RequestParam String upPath ,
log.info("upPath:[{}][{}]", request.getParameter("upPath"), request.getAttribute("upPath"));
String upPath = "/tpl/";
log.info("username[{}],upPath[{}]开始上传文件", SessionUtil.getUserInfo().getMember().getAccNo(), upPath);
String rootPath = request.getSession().getServletContext().getRealPath("/");
log.debug("获取到项目根路径为rootPath[{}]", rootPath);
ShiroHttpServletRequest shiroRequest = (ShiroHttpServletRequest) request;
CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver();
MultipartHttpServletRequest multipartRequest = commonsMultipartResolver.resolveMultipart((HttpServletRequest) shiroRequest.getRequest());
Iterator<String> itr = multipartRequest.getFileNames();
MultipartFile file = null;
while (itr.hasNext()) {
file = multipartRequest.getFile(itr.next());
long pre = System.currentTimeMillis();
if (file != null) {
if (StringUtils.isNotBlank(file.getOriginalFilename())) {
String fileName = StringUtil.combinationString(upPath, "/", file.getOriginalFilename());
String path = rootPath + fileName;
File localFile = new File(path);
file.transferTo(localFile);
}
}
long finaltime = System.currentTimeMillis();
log.info("上传文件耗时:{}" , (finaltime - pre));
}
return "file/success";
}
示例2: Request
import org.springframework.web.multipart.commons.CommonsMultipartResolver; //导入方法依赖的package包/类
public Request(HttpServletRequest servletRequest, ApplicationInstance application) throws IOException {
if (logger.isDebugEnabled()) {
logger.debug("Content-Type: " + servletRequest.getContentType() + ", charset=" + servletRequest.getCharacterEncoding());
}
this.servletRequest = servletRequest;
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
if (multipartResolver.isMultipart(servletRequest)) {
MultipartHttpServletRequest mpr = multipartResolver.resolveMultipart(servletRequest);
this.servletRequest = mpr;
body = mpr.getFileMap();
} else if (StringUtils.startsWithIgnoreCase(this.servletRequest.getContentType(), "application/json")) {
byte[] bytes = IOUtils.toByteArray(this.servletRequest.getInputStream());
String charset = this.servletRequest.getCharacterEncoding();
if (StringUtils.isEmpty(charset)) {
charset = application.getApplication().getCharsetEncoding();
}
String s = new String(bytes, charset);
ObjectMapper mapper = new ObjectMapper();
body = mapper.readValue(s, Object.class);
}
requestAttributeMap = new RequestAttributeMap(this.servletRequest);
requestHeaderMap = new RequestHeaderMap(this.servletRequest);
requestParameterMap = new RequestParameterMap(this.servletRequest);
}
示例3: doPost
import org.springframework.web.multipart.commons.CommonsMultipartResolver; //导入方法依赖的package包/类
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
MultipartHttpServletRequest httpServletRequest = multipartResolver.resolveMultipart(request);
Map<String, MultipartFile> map = httpServletRequest.getFileMap();
MultipartFile multipartFile = map.values().iterator().next();
receivedFiles.add(multipartFile.getOriginalFilename());
}