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


Java MultipartHttpServletRequest.getFiles方法代码示例

本文整理汇总了Java中org.springframework.web.multipart.MultipartHttpServletRequest.getFiles方法的典型用法代码示例。如果您正苦于以下问题:Java MultipartHttpServletRequest.getFiles方法的具体用法?Java MultipartHttpServletRequest.getFiles怎么用?Java MultipartHttpServletRequest.getFiles使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.multipart.MultipartHttpServletRequest的用法示例。


在下文中一共展示了MultipartHttpServletRequest.getFiles方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: resolveName

import org.springframework.web.multipart.MultipartHttpServletRequest; //导入方法依赖的package包/类
@Override
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest webRequest) throws Exception {
	Object arg;

	HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
	MultipartHttpServletRequest multipartRequest =
		WebUtils.getNativeRequest(servletRequest, MultipartHttpServletRequest.class);

	if (MultipartFile.class.equals(parameter.getParameterType())) {
		assertIsMultipartRequest(servletRequest);
		Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?");
		arg = multipartRequest.getFile(name);
	}
	else if (isMultipartFileCollection(parameter)) {
		assertIsMultipartRequest(servletRequest);
		Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?");
		arg = multipartRequest.getFiles(name);
	}
	else if(isMultipartFileArray(parameter)) {
		assertIsMultipartRequest(servletRequest);
		Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?");
		arg = multipartRequest.getFiles(name).toArray(new MultipartFile[0]);
	}
	else if ("javax.servlet.http.Part".equals(parameter.getParameterType().getName())) {
		assertIsMultipartRequest(servletRequest);
		arg = servletRequest.getPart(name);
	}
	else if (isPartCollection(parameter)) {
		assertIsMultipartRequest(servletRequest);
		arg = new ArrayList<Object>(servletRequest.getParts());
	}
	else if (isPartArray(parameter)) {
		assertIsMultipartRequest(servletRequest);
		arg = RequestPartResolver.resolvePart(servletRequest);
	}
	else {
		arg = null;
		if (multipartRequest != null) {
			List<MultipartFile> files = multipartRequest.getFiles(name);
			if (!files.isEmpty()) {
				arg = (files.size() == 1 ? files.get(0) : files);
			}
		}
		if (arg == null) {
			String[] paramValues = webRequest.getParameterValues(name);
			if (paramValues != null) {
				arg = paramValues.length == 1 ? paramValues[0] : paramValues;
			}
		}
	}

	return arg;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:54,代码来源:RequestParamMethodArgumentResolver.java

示例3: resolveArgument

import org.springframework.web.multipart.MultipartHttpServletRequest; //导入方法依赖的package包/类
@Override
@UsesJava8
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
		NativeWebRequest request, WebDataBinderFactory binderFactory) throws Exception {

	HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class);
	assertIsMultipartRequest(servletRequest);

	MultipartHttpServletRequest multipartRequest =
			WebUtils.getNativeRequest(servletRequest, MultipartHttpServletRequest.class);

	Class<?> paramType = parameter.getParameterType();
	boolean optional = paramType.getName().equals("java.util.Optional");
	if (optional) {
		parameter.increaseNestingLevel();
		paramType = parameter.getNestedParameterType();
	}

	String partName = getPartName(parameter);
	Object arg;

	if (MultipartFile.class == paramType) {
		Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?");
		arg = multipartRequest.getFile(partName);
	}
	else if (isMultipartFileCollection(parameter)) {
		Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?");
		arg = multipartRequest.getFiles(partName);
	}
	else if (isMultipartFileArray(parameter)) {
		Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?");
		List<MultipartFile> files = multipartRequest.getFiles(partName);
		arg = files.toArray(new MultipartFile[files.size()]);
	}
	else if ("javax.servlet.http.Part".equals(paramType.getName())) {
		assertIsMultipartRequest(servletRequest);
		arg = servletRequest.getPart(partName);
	}
	else if (isPartCollection(parameter)) {
		assertIsMultipartRequest(servletRequest);
		arg = new ArrayList<Object>(servletRequest.getParts());
	}
	else if (isPartArray(parameter)) {
		assertIsMultipartRequest(servletRequest);
		arg = RequestPartResolver.resolvePart(servletRequest);
	}
	else {
		try {
			HttpInputMessage inputMessage = new RequestPartServletServerHttpRequest(servletRequest, partName);
			arg = readWithMessageConverters(inputMessage, parameter, parameter.getNestedGenericParameterType());
			WebDataBinder binder = binderFactory.createBinder(request, arg, partName);
			if (arg != null) {
				validateIfApplicable(binder, parameter);
				if (binder.getBindingResult().hasErrors() && isBindExceptionRequired(binder, parameter)) {
					throw new MethodArgumentNotValidException(parameter, binder.getBindingResult());
				}
			}
			mavContainer.addAttribute(BindingResult.MODEL_KEY_PREFIX + partName, binder.getBindingResult());
		}
		catch (MissingServletRequestPartException ex) {
			// handled below
			arg = null;
		}
	}

	RequestPart requestPart = parameter.getParameterAnnotation(RequestPart.class);
	boolean isRequired = ((requestPart == null || requestPart.required()) && !optional);

	if (arg == null && isRequired) {
		throw new MissingServletRequestPartException(partName);
	}
	if (optional) {
		arg = Optional.ofNullable(arg);
	}

	return arg;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:78,代码来源:RequestPartMethodArgumentResolver.java

示例4: resolveName

import org.springframework.web.multipart.MultipartHttpServletRequest; //导入方法依赖的package包/类
@Override
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest webRequest) throws Exception {
	HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
	MultipartHttpServletRequest multipartRequest =
			WebUtils.getNativeRequest(servletRequest, MultipartHttpServletRequest.class);
	Object arg;

	if (MultipartFile.class == parameter.getParameterType()) {
		assertIsMultipartRequest(servletRequest);
		Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?");
		arg = multipartRequest.getFile(name);
	}
	else if (isMultipartFileCollection(parameter)) {
		assertIsMultipartRequest(servletRequest);
		Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?");
		arg = multipartRequest.getFiles(name);
	}
	else if (isMultipartFileArray(parameter)) {
		assertIsMultipartRequest(servletRequest);
		Assert.notNull(multipartRequest, "Expected MultipartHttpServletRequest: is a MultipartResolver configured?");
		List<MultipartFile> multipartFiles = multipartRequest.getFiles(name);
		arg = multipartFiles.toArray(new MultipartFile[multipartFiles.size()]);
	}
	else if ("javax.servlet.http.Part".equals(parameter.getParameterType().getName())) {
		assertIsMultipartRequest(servletRequest);
		arg = servletRequest.getPart(name);
	}
	else if (isPartCollection(parameter)) {
		assertIsMultipartRequest(servletRequest);
		arg = new ArrayList<Object>(servletRequest.getParts());
	}
	else if (isPartArray(parameter)) {
		assertIsMultipartRequest(servletRequest);
		arg = RequestPartResolver.resolvePart(servletRequest);
	}
	else {
		arg = null;
		if (multipartRequest != null) {
			List<MultipartFile> files = multipartRequest.getFiles(name);
			if (!files.isEmpty()) {
				arg = (files.size() == 1 ? files.get(0) : files);
			}
		}
		if (arg == null) {
			String[] paramValues = webRequest.getParameterValues(name);
			if (paramValues != null) {
				arg = (paramValues.length == 1 ? paramValues[0] : paramValues);
			}
		}
	}

	return arg;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:54,代码来源:RequestParamMethodArgumentResolver.java


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