當前位置: 首頁>>代碼示例>>Java>>正文


Java MultipartResolver類代碼示例

本文整理匯總了Java中org.springframework.web.multipart.MultipartResolver的典型用法代碼示例。如果您正苦於以下問題:Java MultipartResolver類的具體用法?Java MultipartResolver怎麽用?Java MultipartResolver使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MultipartResolver類屬於org.springframework.web.multipart包,在下文中一共展示了MultipartResolver類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: multipartResolver

import org.springframework.web.multipart.MultipartResolver; //導入依賴的package包/類
@Bean
public MultipartResolver multipartResolver() {
	return new StandardServletMultipartResolver() {
		@Override
		public boolean isMultipart(HttpServletRequest request) {
			String method = request.getMethod().toLowerCase();
			// By default, only POST is allowed. Since this is an 'update'
			// we should accept PUT.
			if (!Arrays.asList("put", "post").contains(method)) {
				return false;
			}
			String contentType = request.getContentType();
			return (contentType != null && contentType.toLowerCase().startsWith("multipart/"));
		}
	};
}
 
開發者ID:scarabsoft,項目名稱:jrest,代碼行數:17,代碼來源:JRestTestApplication.java

示例2: initMultipartResolver

import org.springframework.web.multipart.MultipartResolver; //導入依賴的package包/類
/**
 * Initialize the MultipartResolver used by this class.
 * <p>If no bean is defined with the given name in the BeanFactory for this namespace,
 * no multipart handling is provided.
 */
private void initMultipartResolver(ApplicationContext context) {
	try {
		this.multipartResolver = context.getBean(MULTIPART_RESOLVER_BEAN_NAME, MultipartResolver.class);
		if (logger.isDebugEnabled()) {
			logger.debug("Using MultipartResolver [" + this.multipartResolver + "]");
		}
	}
	catch (NoSuchBeanDefinitionException ex) {
		// Default is no multipart resolver.
		this.multipartResolver = null;
		if (logger.isDebugEnabled()) {
			logger.debug("Unable to locate MultipartResolver with name '" + MULTIPART_RESOLVER_BEAN_NAME +
					"': no multipart request handling provided");
		}
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:22,代碼來源:DispatcherServlet.java

示例3: multipartResolver

import org.springframework.web.multipart.MultipartResolver; //導入依賴的package包/類
@Bean
public MultipartResolver multipartResolver(WikiConfig wikiConfig) {
    final String UPLOAD_TEMP_DIR = wikiConfig.getUploadTempDir();
    //
    CommonsMultipartResolver mr = new CommonsMultipartResolver();
    mr.setMaxUploadSize(MAX_UPLOAD_SIZE);
    mr.setDefaultEncoding(DEFAULT_ENCODING);
    try {
        Resource uploadTempDir = resourceLoader
                .getResource(UPLOAD_TEMP_DIR);
        mr.setUploadTempDir(uploadTempDir);
        LOG.debug(String.format("UPLOAD TEMP DIR = %s", uploadTempDir));
    } catch (IOException e) {
        LOG.error(String.format("#getResource(%s) FAIL, FALLBACK.",
                UPLOAD_TEMP_DIR), e);
    }
    return mr;
}
 
開發者ID:ageldama,項目名稱:glados-wiki,代碼行數:19,代碼來源:MultipartResolverContext.java

示例4: multipartResolver

import org.springframework.web.multipart.MultipartResolver; //導入依賴的package包/類
@Bean(name = "multipartResolver")
public MultipartResolver multipartResolver() {
    CommonsMultipartResolver resolver = new CommonsMultipartResolver();
    resolver.setDefaultEncoding("UTF-8");
    resolver.setMaxInMemorySize(40960);
    resolver.setMaxUploadSize(50 * 1024 * 1024);//上傳文件大小 50M 50*1024*1024
    return resolver;
}
 
開發者ID:lemon-china,項目名稱:lemon-fileservice,代碼行數:9,代碼來源:SpringConfiguration.java

示例5: doFilterInternal

import org.springframework.web.multipart.MultipartResolver; //導入依賴的package包/類
/**
 * Check for a multipart request via this filter's MultipartResolver,
 * and wrap the original request with a MultipartHttpServletRequest if appropriate.
 * <p>All later elements in the filter chain, most importantly servlets, benefit
 * from proper parameter extraction in the multipart case, and are able to cast to
 * MultipartHttpServletRequest if they need to.
 */
@Override
protected void doFilterInternal(
		HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
		throws ServletException, IOException {

	MultipartResolver multipartResolver = lookupMultipartResolver(request);

	HttpServletRequest processedRequest = request;
	if (multipartResolver.isMultipart(processedRequest)) {
		if (logger.isDebugEnabled()) {
			logger.debug("Resolving multipart request [" + processedRequest.getRequestURI() +
					"] with MultipartFilter");
		}
		processedRequest = multipartResolver.resolveMultipart(processedRequest);
	}
	else {
		if (logger.isDebugEnabled()) {
			logger.debug("Request [" + processedRequest.getRequestURI() + "] is not a multipart request");
		}
	}

	try {
		filterChain.doFilter(processedRequest, response);
	}
	finally {
		if (processedRequest instanceof MultipartHttpServletRequest) {
			multipartResolver.cleanupMultipart((MultipartHttpServletRequest) processedRequest);
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:38,代碼來源:MultipartFilter.java

示例6: lookupMultipartResolver

import org.springframework.web.multipart.MultipartResolver; //導入依賴的package包/類
/**
 * Look for a MultipartResolver bean in the root web application context.
 * Supports a "multipartResolverBeanName" filter init param; the default
 * bean name is "filterMultipartResolver".
 * <p>This can be overridden to use a custom MultipartResolver instance,
 * for example if not using a Spring web application context.
 * @return the MultipartResolver instance, or {@code null} if none found
 */
protected MultipartResolver lookupMultipartResolver() {
	WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	String beanName = getMultipartResolverBeanName();
	if (wac != null && wac.containsBean(beanName)) {
		if (logger.isDebugEnabled()) {
			logger.debug("Using MultipartResolver '" + beanName + "' for MultipartFilter");
		}
		return wac.getBean(beanName, MultipartResolver.class);
	}
	else {
		return this.defaultMultipartResolver;
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:22,代碼來源:MultipartFilter.java

示例7: dispatcherServletRefresh

import org.springframework.web.multipart.MultipartResolver; //導入依賴的package包/類
@Test
public void dispatcherServletRefresh() throws ServletException {
	MockServletContext servletContext = new MockServletContext("org/springframework/web/context");
	DispatcherServlet servlet = new DispatcherServlet();

	servlet.init(new MockServletConfig(servletContext, "empty"));
	ServletContextAwareBean contextBean =
			(ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
	ServletConfigAwareBean configBean =
			(ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
	assertSame(servletContext, contextBean.getServletContext());
	assertSame(servlet.getServletConfig(), configBean.getServletConfig());
	MultipartResolver multipartResolver = servlet.getMultipartResolver();
	assertNotNull(multipartResolver);

	servlet.refresh();

	ServletContextAwareBean contextBean2 =
			(ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
	ServletConfigAwareBean configBean2 =
			(ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
	assertSame(servletContext, contextBean2.getServletContext());
	assertSame(servlet.getServletConfig(), configBean2.getServletConfig());
	assertNotSame(contextBean, contextBean2);
	assertNotSame(configBean, configBean2);
	MultipartResolver multipartResolver2 = servlet.getMultipartResolver();
	assertNotSame(multipartResolver, multipartResolver2);

	servlet.destroy();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:31,代碼來源:DispatcherServletTests.java

示例8: dispatcherServletContextRefresh

import org.springframework.web.multipart.MultipartResolver; //導入依賴的package包/類
@Test
public void dispatcherServletContextRefresh() throws ServletException {
	MockServletContext servletContext = new MockServletContext("org/springframework/web/context");
	DispatcherServlet servlet = new DispatcherServlet();

	servlet.init(new MockServletConfig(servletContext, "empty"));
	ServletContextAwareBean contextBean =
			(ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
	ServletConfigAwareBean configBean =
			(ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
	assertSame(servletContext, contextBean.getServletContext());
	assertSame(servlet.getServletConfig(), configBean.getServletConfig());
	MultipartResolver multipartResolver = servlet.getMultipartResolver();
	assertNotNull(multipartResolver);

	((ConfigurableApplicationContext) servlet.getWebApplicationContext()).refresh();

	ServletContextAwareBean contextBean2 =
			(ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
	ServletConfigAwareBean configBean2 =
			(ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
	assertSame(servletContext, contextBean2.getServletContext());
	assertSame(servlet.getServletConfig(), configBean2.getServletConfig());
	assertTrue(contextBean != contextBean2);
	assertTrue(configBean != configBean2);
	MultipartResolver multipartResolver2 = servlet.getMultipartResolver();
	assertTrue(multipartResolver != multipartResolver2);

	servlet.destroy();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:31,代碼來源:DispatcherServletTests.java

示例9: doFilterInternal

import org.springframework.web.multipart.MultipartResolver; //導入依賴的package包/類
/**
 * Check for a multipart request via this filter's MultipartResolver,
 * and wrap the original request with a MultipartHttpServletRequest if appropriate.
 * <p>All later elements in the filter chain, most importantly servlets, benefit
 * from proper parameter extraction in the multipart case, and are able to cast to
 * MultipartHttpServletRequest if they need to.
 */
@Override
protected void doFilterInternal(
		HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
		throws ServletException, IOException {

	MultipartResolver multipartResolver = lookupMultipartResolver(request);

	HttpServletRequest processedRequest = request;
	if (multipartResolver.isMultipart(processedRequest)) {
		if (logger.isDebugEnabled()) {
			logger.debug("Resolving multipart request [" + processedRequest.getRequestURI() +
					"] with MultipartFilter");
		}
		processedRequest = multipartResolver.resolveMultipart(processedRequest);
	}
	else {
		// A regular request...
		if (logger.isDebugEnabled()) {
			logger.debug("Request [" + processedRequest.getRequestURI() + "] is not a multipart request");
		}
	}

	try {
		filterChain.doFilter(processedRequest, response);
	}
	finally {
		if (processedRequest instanceof MultipartHttpServletRequest) {
			multipartResolver.cleanupMultipart((MultipartHttpServletRequest) processedRequest);
		}
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:39,代碼來源:MultipartFilter.java

示例10: multipartResolver

import org.springframework.web.multipart.MultipartResolver; //導入依賴的package包/類
@Bean
@ConditionalOnBean(MultipartResolver.class)
@ConditionalOnMissingBean(name = DispatcherServlet.MULTIPART_RESOLVER_BEAN_NAME)
public MultipartResolver multipartResolver(MultipartResolver resolver) {
	// Detect if the user has created a MultipartResolver but named it incorrectly
	return resolver;
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:8,代碼來源:DispatcherServletAutoConfiguration.java

示例11: containerWithNothing

import org.springframework.web.multipart.MultipartResolver; //導入依賴的package包/類
@Test
public void containerWithNothing() throws Exception {
	this.context = new AnnotationConfigEmbeddedWebApplicationContext(
			ContainerWithNothing.class, BaseConfiguration.class);
	DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class);
	verify404();
	assertThat(servlet.getMultipartResolver()).isNotNull();
	assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class))
			.hasSize(1);
	assertThat(this.context.getBeansOfType(MultipartResolver.class)).hasSize(1);
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:12,代碼來源:MultipartAutoConfigurationTests.java

示例12: containerWithNoMultipartJettyConfiguration

import org.springframework.web.multipart.MultipartResolver; //導入依賴的package包/類
@Test
public void containerWithNoMultipartJettyConfiguration() {
	this.context = new AnnotationConfigEmbeddedWebApplicationContext(
			ContainerWithNoMultipartJetty.class, BaseConfiguration.class);
	DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class);
	assertThat(servlet.getMultipartResolver()).isNotNull();
	assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class))
			.hasSize(1);
	assertThat(this.context.getBeansOfType(MultipartResolver.class)).hasSize(1);
	verifyServletWorks();
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:12,代碼來源:MultipartAutoConfigurationTests.java

示例13: containerWithNoMultipartUndertowConfiguration

import org.springframework.web.multipart.MultipartResolver; //導入依賴的package包/類
@Test
public void containerWithNoMultipartUndertowConfiguration() {
	this.context = new AnnotationConfigEmbeddedWebApplicationContext(
			ContainerWithNoMultipartUndertow.class, BaseConfiguration.class);
	DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class);
	verifyServletWorks();
	assertThat(servlet.getMultipartResolver()).isNotNull();
	assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class))
			.hasSize(1);
	assertThat(this.context.getBeansOfType(MultipartResolver.class)).hasSize(1);
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:12,代碼來源:MultipartAutoConfigurationTests.java

示例14: containerWithNoMultipartTomcatConfiguration

import org.springframework.web.multipart.MultipartResolver; //導入依賴的package包/類
@Test
public void containerWithNoMultipartTomcatConfiguration() {
	this.context = new AnnotationConfigEmbeddedWebApplicationContext(
			ContainerWithNoMultipartTomcat.class, BaseConfiguration.class);
	DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class);
	assertThat(servlet.getMultipartResolver()).isNull();
	assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class))
			.hasSize(1);
	assertThat(this.context.getBeansOfType(MultipartResolver.class)).hasSize(1);
	verifyServletWorks();
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:12,代碼來源:MultipartAutoConfigurationTests.java

示例15: containerWithCustomMultipartResolver

import org.springframework.web.multipart.MultipartResolver; //導入依賴的package包/類
@Test
public void containerWithCustomMultipartResolver() throws Exception {
	this.context = new AnnotationConfigEmbeddedWebApplicationContext(
			ContainerWithCustomMultipartResolver.class, BaseConfiguration.class);
	MultipartResolver multipartResolver = this.context
			.getBean(MultipartResolver.class);
	assertThat(multipartResolver)
			.isNotInstanceOf(StandardServletMultipartResolver.class);
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:10,代碼來源:MultipartAutoConfigurationTests.java


注:本文中的org.springframework.web.multipart.MultipartResolver類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。