本文整理匯總了Java中org.springframework.web.multipart.MultipartHttpServletRequest類的典型用法代碼示例。如果您正苦於以下問題:Java MultipartHttpServletRequest類的具體用法?Java MultipartHttpServletRequest怎麽用?Java MultipartHttpServletRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MultipartHttpServletRequest類屬於org.springframework.web.multipart包,在下文中一共展示了MultipartHttpServletRequest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: saveOrUpdate
import org.springframework.web.multipart.MultipartHttpServletRequest; //導入依賴的package包/類
@RequestMapping(value = "/save.d", produces = "application/json;charset=UTF-8")
public String saveOrUpdate(MultipartHttpServletRequest multipartReq, MoFeatured moFeatured, Model model) {
try {
if (moFeatured.getPicType() == 3) {
String bigPics = StringUtils.defaultIfEmpty(moFeatured.getBigPics(), "").replace(",,", "");
moFeatured.setBigPics(StringUtils.stripEnd(StringUtils.stripStart(bigPics, ","), ","));
} else {
String pics = StringUtils.defaultIfEmpty(moFeatured.getPics(), "").replace(",,", "");
moFeatured.setPics(StringUtils.stripEnd(StringUtils.stripStart(pics, ","), ","));
}
moFeaturedService.saveOrUpdate(multipartReq, moFeatured);
model.addAttribute("rstCode", 0);
} catch (Exception e) {
model.addAttribute("rstCode", 1);
}
return "/moFeatured/save";
}
示例2: 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;
MultipartFile file = multiRequest.getFile("file");
MultipartFile output = multiRequest.getFile("output");
String tags = request.getParameter("tags");
String content = request.getParameter("content");
String url = request.getParameter("url");
String name = file.getOriginalFilename();
name = name.substring(0, name.indexOf('.'));
if(tags == null || content.length() < 5 || content.length() >50 || file == null){ // 태그가 없을 때
model.addAttribute("say", "잘못 입력하셨습니다!!!");
model.addAttribute("url", "/code/");
return "/alert";
}
List<String> tagList = this.tagService.stringToTagList(tags);
Weaver weaver = this.weaverService.getCurrentWeaver();
if(!this.codeService.add(new Code(weaver, name, content,url, tagList), file,output)){ // 태그가 없을 때
model.addAttribute("say", "코드 업로드에 실패하였습니다! 압축파일을 확인하시거나 제대로된 소스파일인지 확인해주세요.");
model.addAttribute("url", "/code/");
return "/alert";
}
return "redirect:/code/";
}
示例3: generate
import org.springframework.web.multipart.MultipartHttpServletRequest; //導入依賴的package包/類
public Swagger generate(){
Swagger swagger = null;
FilterableClassScanner classScanner = new FilterableClassScanner();
classScanner.includePackage(basePackage);
FilterableModelScanner modelScanner = new FilterableModelScanner();
modelScanner.excludePackage("javax.servlet.http");
final SwaggerConfiguration.Builder builder = new SwaggerConfiguration.Builder("", classScanner);
builder.setModelScanner(modelScanner);
if(classLoader != null) {
builder.setClassLoader(classLoader);
} else{
builder.setClassLoader(Thread.currentThread().getContextClassLoader());
}
if(swaggerInfo != null) {
builder.setInfo(swaggerInfo);
} else {
builder.setInfo(new Info());
}
swagger = ResourceClassLoaderUtils.runInClassLoaderContext(new WMCallable<Swagger>() {
@Override
public Swagger call() {
builder.addParameterResolver(Pageable.class, new PageParameterResolver());
builder.addParameterResolver(MultipartFile.class, new MultiPartFileResolver());
builder.addParameterResolver(MultipartHttpServletRequest.class, new MultiPartRequestResolver());
builder.addParameterResolver(HttpServletRequest.class, new ServletMetaTypesResolver());
builder.addParameterResolver(HttpServletResponse.class, new ServletMetaTypesResolver());
SwaggerParser swaggerParser = new SpringSwaggerParser(builder.build());
return swaggerParser.generate();
}
}, classLoader);
return swagger;
}
示例4: resolveArgument
import org.springframework.web.multipart.MultipartHttpServletRequest; //導入依賴的package包/類
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
MultipartHttpServletRequest multipartRequest = WebUtils.getNativeRequest(servletRequest, MultipartHttpServletRequest.class);
ExcelRequestBody annotation = parameter.getParameterAnnotation(ExcelRequestBody.class);
if (multipartRequest != null) {
List<Object> result = new ArrayList<>();
List<MultipartFile> files = multipartRequest.getFiles(annotation.name());
for (MultipartFile file : files) {
if (converters.supportsExcelType(annotation.type())) {
List<?> part = converters.fromExcel(annotation, file.getInputStream());
result.addAll(part);
}
}
return result;
}
return null;
}
示例5: uploadExcel
import org.springframework.web.multipart.MultipartHttpServletRequest; //導入依賴的package包/類
@RequestMapping(value="uploadexcle",method={RequestMethod.GET,RequestMethod.POST})
public String uploadExcel(HttpServletRequest request, Model model) throws Exception {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
InputStream in =null;
List<List<Object>> list = null;
MultipartFile file = multipartRequest.getFile("upfile");
if(file.isEmpty()){
throw new Exception("文件不存在!");
}
in = file.getInputStream();
list = teacherService.getListByExcel(in,file.getOriginalFilename());
in.close();
model.addAttribute("list",list);
return "admin/teacher/upload";
}
示例6: RequestPartServletServerHttpRequest
import org.springframework.web.multipart.MultipartHttpServletRequest; //導入依賴的package包/類
/**
* Create a new instance.
* @param request the current request
* @param partName the name of the part to adapt to the {@link ServerHttpRequest} contract
* @throws MissingServletRequestPartException if the request part cannot be found
* @throws IllegalArgumentException if MultipartHttpServletRequest cannot be initialized
*/
public RequestPartServletServerHttpRequest(HttpServletRequest request, String partName)
throws MissingServletRequestPartException {
super(request);
this.multipartRequest = asMultipartRequest(request);
this.partName = partName;
this.headers = this.multipartRequest.getMultipartHeaders(this.partName);
if (this.headers == null) {
if (request instanceof MultipartHttpServletRequest) {
throw new MissingServletRequestPartException(partName);
}
else {
throw new IllegalArgumentException(
"Failed to obtain request part: " + partName + ". " +
"The part is missing or multipart processing is not configured. " +
"Check for a MultipartResolver bean or if Servlet 3.0 multipart processing is enabled.");
}
}
}
示例7: 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;
}
示例8: uploadFile
import org.springframework.web.multipart.MultipartHttpServletRequest; //導入依賴的package包/類
/**
* 上傳文件
* @param request
* @return
*/
public File uploadFile(HttpServletRequest request) {
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(request.getSession().getServletContext());
try {
if (multipartResolver.isMultipart(request)) {
MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
Iterator<String> iterator = multiRequest.getFileNames();
while (iterator.hasNext()) {
String key = iterator.next();
MultipartFile multipartFile = multiRequest.getFile(key);
if (multipartFile != null) {
String name = multipartFile.getOriginalFilename();
String pathDir = request.getSession().getServletContext().getRealPath("/upload/" + DateUtils.currentTime());
File dirFile = new File(pathDir);
if (!dirFile.isDirectory()) {
dirFile.mkdirs();
}
String filePath = pathDir+File.separator+name;
File file = new File(filePath);
file.setWritable(true, false);
multipartFile.transferTo(file);
return file;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例9: upload
import org.springframework.web.multipart.MultipartHttpServletRequest; //導入依賴的package包/類
/**
* 上傳文件.
* @param request 請求
* @param paraName 文件參數名
* @param baseDir 基本目錄
* @param dir 文件相對目錄
* @return 文件名
* @throws IOException IO異常
*/
public static List<String> upload(HttpServletRequest request, String paraName, String baseDir, String dir) throws IOException {
List<String> fileNames = null;
if (request instanceof MultipartHttpServletRequest) {
List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles(paraName);
fileNames = new ArrayList<>(files.size());
String originalName;
String newName;
for (MultipartFile file : files) {
if (file.isEmpty()) {
continue;
}
File dic = new File(baseDir + dir);
if (!dic.exists()) {
dic.mkdirs();
}
originalName = file.getOriginalFilename();
newName = UUIDGenerator.getFileName() + originalName.substring(originalName.lastIndexOf("."));
Files.copy(file.getInputStream(), Paths.get(baseDir + dir + "/" + newName));
fileNames.add(dir + "/" + newName);
}
}
return fileNames;
}
示例10: updateLogo
import org.springframework.web.multipart.MultipartHttpServletRequest; //導入依賴的package包/類
@RequestMapping(value = "/rolling/upd-logo.d", produces = "application/json;charset=UTF-8")
@ResponseBody
public String updateLogo(MultipartHttpServletRequest multipartReq, @RequestParam int id) {
JSONObject output = new JSONObject();
JSONObject server = new JSONObject();
output.put("result", server);
try {
appService.updateLogo(multipartReq, id);
server.put("code", SvrResult.OK.getCode());
server.put("msg", SvrResult.OK.getMsg());
} catch (Exception e) {
logger.error("Exception", e);
server.put("code", SvrResult.ERROR.getCode());
server.put("msg", SvrResult.ERROR.getMsg());
}
return output.toJSONString(jsonStyle);
}
示例11: saveOrUpdate
import org.springframework.web.multipart.MultipartHttpServletRequest; //導入依賴的package包/類
@RequestMapping(value = "/save.d", produces = "application/json;charset=UTF-8")
// @ResponseBody
public String saveOrUpdate(MultipartHttpServletRequest multipartReq, Metro metro) {
logger.debug("receiving...metro save.");
JSONObject output = new JSONObject();
JSONObject server = new JSONObject();
output.put("result", server);
try {
String pics = StringUtils.defaultIfEmpty(metro.getPics(), "").replace(",,", "");
metro.setPics(StringUtils.stripEnd(StringUtils.stripStart(pics, ","), ","));
metroService.saveOrUpdate(multipartReq, metro);
} catch (Exception e) {
logger.error("Exception", e);
}
return "/metro/save";
}
示例12: updateIndexImg
import org.springframework.web.multipart.MultipartHttpServletRequest; //導入依賴的package包/類
public void updateIndexImg(MultipartHttpServletRequest multipartReq, MarketApp marketApp) throws IOException,
MalformedURLException, URISyntaxException {
int id = marketApp.getId();
// 大遊戲首頁圖片.瀏覽器上傳用戶本地文件 或 下載遠端服務器 圖片.
String indexImgUrlBak = multipartReq.getParameter("oldIndexImgUrl"); // app.getIndexImgUrl();
boolean needToDeleteIndexImgUrlBak = false;
String remoteIndexImgUrl = multipartReq.getParameter("remoteIndexImgUrl");
MultipartFile file = multipartReq.getFile("indexImgFile");
String subPath = null;
if (file != null && !file.isEmpty()) {
subPath = attachmentService.saveMarketAppFile(id, file);
} else if (StringUtils.isNotBlank(remoteIndexImgUrl)) {
// 拉取圖片.
subPath = attachmentService.saveMarketAppFile(id, remoteIndexImgUrl);
}
if (StringUtils.isNotBlank(subPath)) {
String indexImgUrl = PathUtils.concate(appConfig.getDestBigGameUploadBaseurl(), subPath);
marketApp.setIndexImgUrl(indexImgUrl);
saveOrUpdate(marketApp);
needToDeleteIndexImgUrlBak = true;
}
if (appConfig.isDeleteUploadImageFile() && StringUtils.isNotBlank(indexImgUrlBak) && needToDeleteIndexImgUrlBak) {
attachmentService.deleteFile(indexImgUrlBak);
}
}
示例13: updateLogo
import org.springframework.web.multipart.MultipartHttpServletRequest; //導入依賴的package包/類
public void updateLogo(MultipartHttpServletRequest multipartReq, MarketApp marketApp) throws IOException,
MalformedURLException, URISyntaxException {
int id = marketApp.getId();
// logo. 瀏覽器上傳用戶本地文件 或 下載遠端服務器 圖片.
String logoUrlBak = multipartReq.getParameter("oldLogoUrl");// app.getLogoUrl();
boolean needToDeleteLogoUrlBak = false;
String remoteLogoUrl = multipartReq.getParameter("remoteLogoUrl");
MultipartFile file = multipartReq.getFile("logoFile");
String logoSubPath = null;
if (file != null && !file.isEmpty()) {
logoSubPath = attachmentService.saveMarketAppFile(id, file);
} else if (StringUtils.isNotBlank(remoteLogoUrl)) {
// 拉取圖片.
logoSubPath = attachmentService.saveMarketAppFile(id, remoteLogoUrl);
}
if (StringUtils.isNotBlank(logoSubPath)) {
String logoUrl = PathUtils.concate(appConfig.getDestBigGameUploadBaseurl(), logoSubPath);
marketApp.setLogoUrl(logoUrl);
saveOrUpdate(marketApp);
needToDeleteLogoUrlBak = true;
}
if (appConfig.isDeleteUploadImageFile() && StringUtils.isNotBlank(logoUrlBak) && needToDeleteLogoUrlBak) {
attachmentService.deleteFile(logoUrlBak);
}
}
示例14: updateIndexImg
import org.springframework.web.multipart.MultipartHttpServletRequest; //導入依賴的package包/類
public void updateIndexImg(MultipartHttpServletRequest multipartReq, App app) throws IOException,
MalformedURLException, URISyntaxException {
int id = app.getId();
// 大遊戲首頁圖片.瀏覽器上傳用戶本地文件 或 下載遠端服務器 圖片.
String indexImgUrlBak = multipartReq.getParameter("oldIndexImgUrl"); // app.getIndexImgUrl();
boolean needToDeleteIndexImgUrlBak = false;
String remoteIndexImgUrl = multipartReq.getParameter("remoteIndexImgUrl");
MultipartFile file = multipartReq.getFile("indexImgFile");
String subPath = null;
if (file != null && !file.isEmpty()) {
subPath = attachmentService.saveFile(id, file);
} else if (StringUtils.isNotBlank(remoteIndexImgUrl)) {
// 拉取圖片.
subPath = attachmentService.saveFile(id, remoteIndexImgUrl);
}
if (StringUtils.isNotBlank(subPath)) {
String indexImgUrl = PathUtils.concate(appConfig.getDestUploadBaseurl(), subPath);
app.setIndexImgUrl(indexImgUrl);
saveOrUpdate(app);
needToDeleteIndexImgUrlBak = true;
}
if (StringUtils.isNotBlank(indexImgUrlBak) && needToDeleteIndexImgUrlBak) {
attachmentService.deleteFile(indexImgUrlBak);
}
}
示例15: getAppTags
import org.springframework.web.multipart.MultipartHttpServletRequest; //導入依賴的package包/類
private List<AppAndTag> getAppTags(MultipartHttpServletRequest multipartReq) {
List<AppAndTag> list = new ArrayList<AppAndTag>();
String[] ids = multipartReq.getParameterValues("appTagId");
String[] appIds = multipartReq.getParameterValues("appId");
String[] tagNames = multipartReq.getParameterValues("tagName");
String[] tagIds = multipartReq.getParameterValues("tagId");
AppAndTag tag = null;
if (ids != null && ids.length > 0) {
for (int i = 0; i < ids.length; i++) {
tag = new AppAndTag();
tag.setId(Integer.valueOf(StringUtils.defaultIfEmpty(ids[i], "0")));
tag.setAppId(Integer.valueOf(StringUtils.defaultIfEmpty(appIds[i], "0")));
tag.setTagId(Integer.valueOf(StringUtils.defaultIfEmpty(tagIds[i], "0")));
tag.setTagName(StringUtils.defaultIfEmpty(tagNames[i], ""));
list.add(tag);
}
}
return list;
}