当前位置: 首页>>代码示例>>Java>>正文


Java MultipartHttpServletRequest类代码示例

本文整理汇总了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";
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:18,代码来源:MoFeaturedController.java

示例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/";
}
 
开发者ID:forweaver,项目名称:forweaver2.0,代码行数:26,代码来源:CodeController.java

示例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;
}
 
开发者ID:wavemaker,项目名称:wavemaker-app-build-tools,代码行数:39,代码来源:SwaggerGenerator.java

示例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;

}
 
开发者ID:natsuforyou,项目名称:spring-boot-excel-plugin,代码行数:22,代码来源:ExcelRequestResponseBodyHandler.java

示例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";
}
 
开发者ID:junrui-zhao,项目名称:Educational-Management-System,代码行数:16,代码来源:TeacherTableController.java

示例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.");
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:RequestPartServletServerHttpRequest.java

示例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;
}
 
开发者ID:xujeff,项目名称:tianti,代码行数:26,代码来源:UploadController.java

示例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;
}
 
开发者ID:babymm,项目名称:mmsns,代码行数:36,代码来源:DocUploadController.java

示例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;
}
 
开发者ID:DomKing,项目名称:springbootWeb,代码行数:33,代码来源:UploadUtil.java

示例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);
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:18,代码来源:AppController.java

示例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";
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:17,代码来源:MetroController.java

示例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);
    }
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:27,代码来源:MarketAppServiceImpl.java

示例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);
    }
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:26,代码来源:MarketAppServiceImpl.java

示例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);
    }
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:27,代码来源:AppServiceImpl.java

示例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;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:20,代码来源:AppServiceImpl.java


注:本文中的org.springframework.web.multipart.MultipartHttpServletRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。