本文整理汇总了Java中org.springframework.web.multipart.MultipartHttpServletRequest.getFileMap方法的典型用法代码示例。如果您正苦于以下问题:Java MultipartHttpServletRequest.getFileMap方法的具体用法?Java MultipartHttpServletRequest.getFileMap怎么用?Java MultipartHttpServletRequest.getFileMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.multipart.MultipartHttpServletRequest
的用法示例。
在下文中一共展示了MultipartHttpServletRequest.getFileMap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ajaxUploadFile
import org.springframework.web.multipart.MultipartHttpServletRequest; //导入方法依赖的package包/类
@RequestMapping("/ajax/upload_file")
@ResponseBody
public AjaxResult ajaxUploadFile(HttpServletRequest request) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
AjaxResult ajaxResult = new AjaxResult();
ajaxResult.setSuccess(false);
try {
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
MultipartFile multipartFile = null;
String fileName = null;
for (Map.Entry<String, MultipartFile> set : fileMap.entrySet()) {
multipartFile = set.getValue();// 文件名
}
fileName = this.storeIOc(multipartRequest, multipartFile);
ajaxResult.setData(fileName);
ajaxResult.setSuccess(true);
} catch (Exception e) {
e.printStackTrace();
}
return ajaxResult;
}
示例2: addRepost
import org.springframework.web.multipart.MultipartHttpServletRequest; //导入方法依赖的package包/类
@RequestMapping(value = "/{codeID}/add-repost", method = RequestMethod.POST)
public String addRepost(@PathVariable("codeID") int codeID,
HttpServletRequest request,Model model) throws UnsupportedEncodingException {
final MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
final Map<String, MultipartFile> files = multiRequest.getFileMap();
String content = request.getParameter("content");
Weaver weaver = this.weaverService.getCurrentWeaver();
Code code = this.codeService.get(codeID,true);
if(code == null || weaver == null || content.equals("")) {
model.addAttribute("say", "잘못 입력하셨습니다!!!");
model.addAttribute("url", "/code/"+codeID);
return "/alert";
}
ArrayList<Data> datas = new ArrayList<Data>();
for (MultipartFile file : files.values()) {
if(!file.isEmpty())
datas.add(new Data(this.dataService.getObjectID(file.getOriginalFilename(), weaver),file,weaver));
}
RePost rePost = new RePost(code,
weaver,
content);
this.rePostService.add(rePost,datas);
code.setRePostCount(code.getRePostCount()+1);
code.setRecentRePostDate(rePost.getCreated());
this.codeService.update(code);
return "redirect:/code/"+codeID;
}
示例3: update
import org.springframework.web.multipart.MultipartHttpServletRequest; //导入方法依赖的package包/类
@RequestMapping(value="/{codeID}/{rePostID}/update", method = RequestMethod.POST)
public String update(@PathVariable("codeID") int codeID, @PathVariable("rePostID") int rePostID,HttpServletRequest request,Model model) throws UnsupportedEncodingException {
final MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
final Map<String, MultipartFile> files = multiRequest.getFileMap();
ArrayList<Data> datas = new ArrayList<Data>();
Code code = this.codeService.get(codeID,true);
RePost rePost = this.rePostService.get(rePostID);
String content = request.getParameter("content");
Weaver weaver = this.weaverService.getCurrentWeaver();
String remove = request.getParameter("remove");
if(code == null || rePost == null || content.length() < 5 ||
rePost.getOriginalCode().getCodeID() != code.getCodeID()){
model.addAttribute("say", "잘못 입력하셨습니다!!!");
model.addAttribute("url", "/code/"+codeID);
return "/alert";
}
if(!rePost.getWriter().equals(weaver) &&
!this.tagService.validateTag(code.getTags(),weaver)){ // 태그에 권한이 없을때
model.addAttribute("say", "권한이 없습니다!!!");
model.addAttribute("url", "/code/"+codeID);
return "/alert";
}
for (MultipartFile file : files.values())
if(!file.isEmpty()){
String fileID= this.dataService.getObjectID(file.getOriginalFilename(), weaver);
if(!fileID.equals(""))
datas.add(new Data(fileID,file,weaver));
}
rePost.setContent(content);
this.rePostService.update(rePost,datas,remove.split("@"));
return "redirect:/code/"+codeID;
}
示例4: addRepost
import org.springframework.web.multipart.MultipartHttpServletRequest; //导入方法依赖的package包/类
@RequestMapping(value = "/{postID}/add-repost", method = RequestMethod.POST)
public String addRepost(@PathVariable("postID") int postID,HttpServletRequest request,Model model) throws UnsupportedEncodingException {
final MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
final Map<String, MultipartFile> files = multiRequest.getFileMap();
String content = request.getParameter("content");
Post post = postService.get(postID);
Weaver weaver = weaverService.getCurrentWeaver();
if(!post.getWriter().equals(weaver) && !tagService.validateTag(post.getTags(),weaver) ||
weaver == null || post == null || content.equals("")) {
model.addAttribute("say", "잘못 입력하셨습니다!!!");
model.addAttribute("url", "/community/"+postID);
return "/alert";
}
ArrayList<Data> datas = new ArrayList<Data>();
for (MultipartFile file : files.values())
if(!file.isEmpty()){
String fileID= dataService.getObjectID(file.getOriginalFilename(), weaver);
if(!fileID.equals(""))
datas.add(new Data(fileID,file,weaver));
}
RePost rePost = new RePost(post,weaver,content);
post.setRecentRePostDate(rePost.getCreated());
post.addRePostCount();
postService.update(post,null, null);
rePostService.add(rePost,datas);
return "redirect:/community/"+postID;
}
示例5: update
import org.springframework.web.multipart.MultipartHttpServletRequest; //导入方法依赖的package包/类
@RequestMapping(value="/{postID}/{rePostID}/update", method = RequestMethod.POST)
public String update(@PathVariable("postID") int postID, @PathVariable("rePostID") int rePostID,HttpServletRequest request,Model model) throws UnsupportedEncodingException {
final MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
final Map<String, MultipartFile> files = multiRequest.getFileMap();
ArrayList<Data> datas = new ArrayList<Data>();
Post post = postService.get(postID);
RePost rePost = rePostService.get(rePostID);
String content = request.getParameter("content");
Weaver weaver = weaverService.getCurrentWeaver();
String remove = request.getParameter("remove");
if(post == null || rePost == null || content.length() < 5 ||
rePost.getOriginalPost().getPostID() != post.getPostID()){ // 태그가 없을 때
model.addAttribute("say", "잘못 입력하셨습니다!!!");
model.addAttribute("url", "/community/"+postID);
return "/alert";
}
if(!rePost.getWriter().equals(weaver) &&
!tagService.validateTag(post.getTags(),weaver)){ // 태그에 권한이 없을때
model.addAttribute("say", "권한이 없습니다!!!");
model.addAttribute("url", "/community/"+postID);
return "/alert";
}
for (MultipartFile file : files.values())
if(!file.isEmpty()){
String fileID= dataService.getObjectID(file.getOriginalFilename(), weaver);
if(!fileID.equals(""))
datas.add(new Data(fileID,file,weaver));
}
rePost.setContent(content);
rePostService.update(rePost,datas,remove.split("@"));
return "redirect:/community/"+postID;
}
示例6: uploadAttach
import org.springframework.web.multipart.MultipartHttpServletRequest; //导入方法依赖的package包/类
@RequestMapping("/uploadAttach")
public void uploadAttach(HttpServletRequest request, PrintWriter out) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
MultipartFile multipartFile = null;
String fileName = null;
for (Map.Entry<String, MultipartFile> set : fileMap.entrySet()) {
multipartFile = set.getValue();// 文件名
}
fileName = this.storeIOc(multipartRequest, multipartFile);
out.print(fileName);
}
示例7: transferSpringRequestStreamToHD
import org.springframework.web.multipart.MultipartHttpServletRequest; //导入方法依赖的package包/类
protected FResult<String> transferSpringRequestStreamToHD(UploadRequest uploadRequest, String saveTempFileDirectory,
HttpServletRequest request) {
MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMaps = multiRequest.getFileMap();
if (fileMaps != null && fileMaps.size() == 1) {
for (Entry<String, MultipartFile> fileEntry : fileMaps.entrySet()) {
if (fileEntry != null && !fileEntry.getValue().isEmpty()) {
// 得到本次上传文件
MultipartFile multiFile = fileEntry.getValue();
String originalFilename = multiFile.getOriginalFilename();
uploadRequest.setOriginalExtName(FilenameUtils.getExtension(originalFilename));
String fileName = UUID.randomUUID().toString() + "." + uploadRequest.getOriginalExtName();
if (StringUtils.isBlank(uploadRequest.getOriginalFilename())) {
uploadRequest.setOriginalFilename(fileName);
} else {
uploadRequest.setOriginalFilename(originalFilename);
}
String fileFullPath = saveTempFileDirectory + File.separator + fileName;
log.debug("file temp path : " + fileFullPath);
// 构造临时文件
File uploadTempFile = new File(fileFullPath);
try {
// 临时文件持久化到硬盘
multiFile.transferTo(uploadTempFile);
uploadRequest.setTemporaryFilePath(fileFullPath);
uploadRequest.setTemporaryFileSize(uploadTempFile.length());
} catch (IllegalStateException | IOException e) {
log.error("上传文件持久化到服务器失败,计划持久化文件 ", e);
return FResult.newFailure(HttpResponseCode.SERVER_IO_ERROR, "上传文件持久化到服务器失败");
}
}
}
return FResult.newSuccess("上传成功");
} else {
return FResult.newFailure(HttpResponseCode.CLIENT_PARAM_INVALID, "一次请求仅支持上传一个文件");
}
}
示例8: doTestMultipartHttpServletRequest
import org.springframework.web.multipart.MultipartHttpServletRequest; //导入方法依赖的package包/类
private void doTestMultipartHttpServletRequest(MultipartHttpServletRequest request) throws IOException {
Set<String> fileNames = new HashSet<String>();
Iterator<String> fileIter = request.getFileNames();
while (fileIter.hasNext()) {
fileNames.add(fileIter.next());
}
assertEquals(2, fileNames.size());
assertTrue(fileNames.contains("file1"));
assertTrue(fileNames.contains("file2"));
MultipartFile file1 = request.getFile("file1");
MultipartFile file2 = request.getFile("file2");
Map<String, MultipartFile> fileMap = request.getFileMap();
List<String> fileMapKeys = new LinkedList<String>(fileMap.keySet());
assertEquals(2, fileMapKeys.size());
assertEquals(file1, fileMap.get("file1"));
assertEquals(file2, fileMap.get("file2"));
assertEquals("file1", file1.getName());
assertEquals("", file1.getOriginalFilename());
assertNull(file1.getContentType());
assertTrue(ObjectUtils.nullSafeEquals("myContent1".getBytes(), file1.getBytes()));
assertTrue(ObjectUtils.nullSafeEquals("myContent1".getBytes(),
FileCopyUtils.copyToByteArray(file1.getInputStream())));
assertEquals("file2", file2.getName());
assertEquals("myOrigFilename", file2.getOriginalFilename());
assertEquals("text/plain", file2.getContentType());
assertTrue(ObjectUtils.nullSafeEquals("myContent2".getBytes(), file2.getBytes()));
assertTrue(ObjectUtils.nullSafeEquals("myContent2".getBytes(),
FileCopyUtils.copyToByteArray(file2.getInputStream())));
}
示例9: uploadFileContent
import org.springframework.web.multipart.MultipartHttpServletRequest; //导入方法依赖的package包/类
/**
* 上传情报正文及附件入口(历史遗留问题,情报系统专用NTKO控件)
* @param request
* @return
* @throws Exception
*/
@RequestMapping(value = "uploadFileContent", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "上传NTKO控件文件", httpMethod = "POST", response = Map.class, notes = "上传NTKO控件文件【情报系统】",
produces="application/json",consumes="application/x-www-form-urlencoded")
public Map<String,String> uploadFileContent(HttpServletRequest request) throws Exception{
Map<String,String> map = Maps.newHashMap();
String fileName = null;
String savePath = null;
ShiroUser user = appUserSession.getCurrentUser();
MultipartFile file = null;
MultipartHttpServletRequest mureq = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> files = mureq.getFileMap();
if (files != null && files.size() != 0) {
for(String key : files.keySet()) {
file=files.get(key);
break;
}
String fileFullPath = Encodes.urlDecode(file.getOriginalFilename()); //NTKO控件新增和上传文件回传的文件名其实是一个http的网络绝对路径
log.debug(fileFullPath);
if(fileFullPath.indexOf("http") == -1 || fileFullPath.indexOf("/static/uploadFiles/") == -1){
fileName = fileFullPath; //新建文件
}else{ //修改已上传文件
fileName = fileFullPath.substring(fileFullPath.lastIndexOf("/"));
}
savePath = appFileUtils.uploadFromClient(file, fileName, "/static/uploadFiles/"+user.getLoginName()+"/"+DateUtil.getToday()+"/");
log.debug(fileName);
log.debug(savePath);
}
map.put("fileName", StringUtils.isEmpty(savePath) ? "": Encodes.urlEncode(fileName));
map.put("filePath", StringUtils.isEmpty(savePath) ? "": Encodes.urlEncode(savePath));
return map;
}
示例10: insertLoginScrinImage
import org.springframework.web.multipart.MultipartHttpServletRequest; //导入方法依赖的package包/类
/**
* 로그인화면이미지정보를 신규로 등록한다.
*
* @param loginScrinImageVO
*/
@RequestMapping(value = "/uss/ion/lsi/insertLoginScrinImage.do")
public String insertLoginScrinImage(
MultipartHttpServletRequest multiRequest,
@ModelAttribute LoginScrinImageVO loginScrinImageVO,
BindingResult bindingResult,
ModelMap model)
throws Exception {
beanValidator.validate(loginScrinImageVO, bindingResult); // validation 수행
if (bindingResult.hasErrors()) {
return WebUtil.adjustViewName("/uss/ion/lsi/LoginScrinImageRegist");
}
String atchFileId = "";
String image = "";
final Map<String, MultipartFile> files = multiRequest.getFileMap();
if (!files.isEmpty()) {
List<FileVO> result = fileUtil.parseFileInf(files, "LSI_", 0, "", "");
atchFileId = fileMngService.insertFileInfs(result);
for(FileVO fileVo : result) {
image = fileVo.getOrignlFileNm();
}
}
loginScrinImageVO.setImageFile(atchFileId);
loginScrinImageVO.setImage(image);
LoginVO loginVO = (LoginVO) UserDetailsHelper.getAuthenticatedUser();
loginScrinImageVO.setUserId(loginVO.getId());
loginScrinImageService.insertLoginScrinImage(loginScrinImageVO);
model.addAttribute("message", MessageHelper.getMessage("success.common.insert"));
return WebUtil.redirectJsp(model, "/uss/ion/lsi/listLoginScrinImage.do");
}
示例11: insertMainImage
import org.springframework.web.multipart.MultipartHttpServletRequest; //导入方法依赖的package包/类
/**
* 메인화면이미지정보를 신규로 등록한다.
*
* @param mainImageVO
*/
@RequestMapping(value = "/uss/ion/msi/insertMainImage.do")
public String insertMainImage(
MultipartHttpServletRequest multiRequest,
@ModelAttribute MainImageVO mainImageVO,
BindingResult bindingResult,
ModelMap model)
throws Exception {
beanValidator.validate(mainImageVO, bindingResult); // validation 수행
if (bindingResult.hasErrors()) {
return WebUtil.adjustViewName("/uss/ion/msi/MainImageRegist");
}
String atchFileId = "";
String image = "";
Map<String, MultipartFile> files = multiRequest.getFileMap();
if (!files.isEmpty()) {
List<FileVO> result = fileUtil.parseFileInf(files, "MSI_", 0, "", "");
atchFileId = fileMngService.insertFileInfs(result);
for(FileVO fileVo : result) {
image = fileVo.getOrignlFileNm();
}
}
mainImageVO.setImageFile(atchFileId);
mainImageVO.setImage(image);
LoginVO loginVO = (LoginVO) UserDetailsHelper.getAuthenticatedUser();
mainImageVO.setUserId(loginVO.getId());
mainImageService.insertMainImage(mainImageVO);
model.addAttribute("message", MessageHelper.getMessage("success.common.insert"));
return WebUtil.redirectJsp(model, "/uss/ion/msi/listMainImage.do");
}
示例12: insertBanner
import org.springframework.web.multipart.MultipartHttpServletRequest; //导入方法依赖的package包/类
/**
* 배너정보를 신규로 등록한다.
*
* @param bannerVO
*/
@RequestMapping(value = "/uss/ion/bnr/insertBanner.do")
public String insertBanner(
MultipartHttpServletRequest multiRequest,
@ModelAttribute BannerVO bannerVO,
BindingResult bindingResult,
ModelMap model)
throws Exception {
beanValidator.validate(bannerVO, bindingResult); // validation 수행
if (bindingResult.hasErrors()) {
return WebUtil.adjustViewName("/uss/ion/bnr/BannerRegist");
}
String atchFileId = "";
String bannerImage = "";
final Map<String, MultipartFile> files = multiRequest.getFileMap();
if (!files.isEmpty()) {
List<FileVO> result = fileUtil.parseFileInf(files, "BNR_", 0, "", "");
atchFileId = fileMngService.insertFileInfs(result);
for(FileVO fileVo : result) {
bannerImage = fileVo.getOrignlFileNm();
}
}
bannerVO.setBannerImageFile(atchFileId);
bannerVO.setBannerImage(bannerImage);
LoginVO loginVO = (LoginVO) UserDetailsHelper.getAuthenticatedUser();
bannerVO.setUserId(loginVO.getId());
bannerService.insertBanner(bannerVO);
model.addAttribute("message", MessageHelper.getMessage("success.common.insert"));
return WebUtil.redirectJsp(model, "/uss/ion/bnr/listBanner.do");
}
示例13: insertMultiFile
import org.springframework.web.multipart.MultipartHttpServletRequest; //导入方法依赖的package包/类
/**
* 첨부파일을 새로 저장한다.
*
* @param multiRequest MultipartHttpServletRequest
* @param KeyStr String
* @return String
* @throws Exception
*/
public String insertMultiFile(MultipartHttpServletRequest multiRequest, String KeyStr)
throws Exception {
String atchFileId = "";
Map<String, MultipartFile> files = multiRequest.getFileMap();
if (!files.isEmpty()) {
List<FileVO> result = parseFileInf(files, KeyStr, 0, "", "");
atchFileId = fileMngService.insertFileInfs(result);
}
return atchFileId;
}
示例14: handleFiles
import org.springframework.web.multipart.MultipartHttpServletRequest; //导入方法依赖的package包/类
private void handleFiles(Integer cid, HttpServletRequest request) {
Assert.state(request instanceof MultipartHttpServletRequest,
"request !instanceof MultipartHttpServletRequest");
final MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
final Map<String, MultipartFile> files = multiRequest.getFileMap();
boolean mkdirs = true;
File dir = new File(Config.getProperty("base.contest.images"),
String.valueOf(cid));
dir.mkdirs();
for (MultipartFile filex : files.values()) {
if (filex.getOriginalFilename() != null
&& !filex.getOriginalFilename().equals("")
&& filex.getSize() > 0) {
String filename = filex.getOriginalFilename();
File file = new File(dir, filename);
if (file.exists() && !file.isDirectory()) {
file.delete();
}
if (mkdirs) {
file.mkdirs();
mkdirs = false;
}
try {
filex.transferTo(file);
String ext = filex.getOriginalFilename().substring(
filex.getOriginalFilename().lastIndexOf("."));
if (ext.equals(".zip") || ext.equals(".rar")) {
FileUtils.decompressFile(file.getAbsolutePath(),
dir.getAbsolutePath(), true);
}
} catch (IOException | IllegalStateException ex) {
Logger.getLogger(ProblemController.class.getName()).log(
java.util.logging.Level.SEVERE, null, ex);
}
}
}
}
示例15: add
import org.springframework.web.multipart.MultipartHttpServletRequest; //导入方法依赖的package包/类
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String add(final HttpServletRequest request,Model model) throws UnsupportedEncodingException {
final MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
final Map<String, MultipartFile> files = multiRequest.getFileMap();
ArrayList<Data> datas = new ArrayList<Data>();
String tags = request.getParameter("tags");
String title = request.getParameter("title");
String content = request.getParameter("content");
if(tags == null || title == null || title.length() < 5 || title.length() > 200
|| (content.length() >0 && content.length() < 5)){ // 검증함
model.addAttribute("say", "잘못 입력하셨습니다!!!");
model.addAttribute("url", "/community/");
return "/alert";
}
List<String> tagList = tagService.stringToTagList(tags);
Weaver weaver = weaverService.getCurrentWeaver();
tagList = tagService.removeMyMassageTag(tagList,weaver);//실수로 자신의 메세지 태그를 붙이면 지움
if(!tagService.validateTag(tagList,weaver)){ // 태그에 권한이 없을때
model.addAttribute("say", "태그에 권한이 없습니다!!!");
model.addAttribute("url", "/community/");
return "/alert";
}
for (MultipartFile file : files.values())
if(!file.isEmpty()){
String fileID= dataService.getObjectID(file.getOriginalFilename(), weaver);
if(!fileID.equals(""))
datas.add(new Data(fileID,file,weaver));
}
Post post = new Post(weaver,title,
content,
tagList);
postService.add(post,datas);
if(postService.isMassageTags(tagList))
return "redirect:"+"/community/tags:"+"$"+weaver.getId();
return "redirect:"+"/community/";
}