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


Java RequestMappingHandlerMapping类代码示例

本文整理汇总了Java中org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping的典型用法代码示例。如果您正苦于以下问题:Java RequestMappingHandlerMapping类的具体用法?Java RequestMappingHandlerMapping怎么用?Java RequestMappingHandlerMapping使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RequestMappingHandlerMapping类属于org.springframework.web.servlet.mvc.method.annotation包,在下文中一共展示了RequestMappingHandlerMapping类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCustomConversionService

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
@Test(expected = TypeMismatchException.class)
public void testCustomConversionService() throws Exception {
	loadBeanDefinitions("mvc-config-custom-conversion-service.xml", 14);

	RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
	assertNotNull(mapping);
	mapping.setDefaultHandler(handlerMethod);

	// default web binding initializer behavior test
	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
	request.setRequestURI("/accounts/12345");
	request.addParameter("date", "2009-10-31");
	MockHttpServletResponse response = new MockHttpServletResponse();

	HandlerExecutionChain chain = mapping.getHandler(request);
	assertEquals(1, chain.getInterceptors().length);
	assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor);
	ConversionServiceExposingInterceptor interceptor = (ConversionServiceExposingInterceptor) chain.getInterceptors()[0];
	interceptor.preHandle(request, response, handler);
	assertSame(appContext.getBean("conversionService"), request.getAttribute(ConversionService.class.getName()));

	RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
	assertNotNull(adapter);
	adapter.handle(request, response, handlerMethod);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:MvcNamespaceTests.java

示例2: onApplicationEvent

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
@Override
public void onApplicationEvent ( ContextRefreshedEvent event ) {
	final RequestMappingHandlerMapping requestMappingHandlerMapping =
		applicationContext.getBean( RequestMappingHandlerMapping.class );
	final Map< RequestMappingInfo, HandlerMethod > handlerMethods =
		requestMappingHandlerMapping.getHandlerMethods();

	this.handlerMethods = handlerMethods;

	handlerMethods.keySet().forEach( mappingInfo -> {
		Map< Set< String >, Set< RequestMethod > > mapping = Collections.singletonMap(
			mappingInfo.getPatternsCondition().getPatterns() ,
			this.getMethods( mappingInfo.getMethodsCondition().getMethods() )
		);
		requestMappingInfos.add( mapping );
	} );

	requestMappingUris.addAll(
		handlerMethods.keySet()
					  .parallelStream()
					  .map( mappingInfo -> mappingInfo.getPatternsCondition().getPatterns() )
					  .collect( Collectors.toList() )
	);

}
 
开发者ID:yujunhao8831,项目名称:spring-boot-start-current,代码行数:26,代码来源:BasicBeanConfig.java

示例3: of

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
public static List<OriginalRequestMappingInfo> of(RequestMappingHandlerMapping handlerMapping) {
    List<OriginalRequestMappingInfo> result = new ArrayList<OriginalRequestMappingInfo>();

    for (Entry<RequestMappingInfo, HandlerMethod> entry : handlerMapping.getHandlerMethods().entrySet()) {
        RequestMappingInfo requestMappingInfo = entry.getKey();

        OriginalRequestMappingInfo o = new OriginalRequestMappingInfo();
        o.setSite(Site.of(requestMappingInfo.getPatternsCondition().getPatterns().iterator().next()));
        o.setMethods(requestMappingInfo.getMethodsCondition().getMethods());
        o.setPatterns(requestMappingInfo.getPatternsCondition().getPatterns());

        Set<String> params = new HashSet<>();
        for (NameValueExpression<String> nameValueExpression : requestMappingInfo.getParamsCondition().getExpressions()) {
            params.add(nameValueExpression.toString());
        }
        o.setParams(params);

        result.add(o);
    }

    return result.stream().sorted().collect(Collectors.toList());
}
 
开发者ID:sinsengumi,项目名称:spring-boot-application-infrastructure,代码行数:23,代码来源:RouterController.java

示例4: doTestCustomValidator

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
private void doTestCustomValidator(String xml) throws Exception {
	loadBeanDefinitions(xml, 14);

	RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
	assertNotNull(mapping);
	assertFalse(mapping.getUrlPathHelper().shouldRemoveSemicolonContent());

	RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
	assertNotNull(adapter);
	assertEquals(true, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));

	// default web binding initializer behavior test
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.addParameter("date", "2009-10-31");
	MockHttpServletResponse response = new MockHttpServletResponse();
	adapter.handle(request, response, handlerMethod);

	assertTrue(appContext.getBean(TestValidator.class).validatorInvoked);
	assertFalse(handler.recordedValidationError);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:MvcNamespaceTests.java

示例5: testBeanDecoration

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
@Test
public void testBeanDecoration() throws Exception {
	loadBeanDefinitions("mvc-config-bean-decoration.xml", 16);

	RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
	assertNotNull(mapping);
	mapping.setDefaultHandler(handlerMethod);

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");

	HandlerExecutionChain chain = mapping.getHandler(request);
	assertEquals(3, chain.getInterceptors().length);
	assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor);
	assertTrue(chain.getInterceptors()[1] instanceof LocaleChangeInterceptor);
	assertTrue(chain.getInterceptors()[2] instanceof ThemeChangeInterceptor);
	LocaleChangeInterceptor interceptor = (LocaleChangeInterceptor) chain.getInterceptors()[1];
	assertEquals("lang", interceptor.getParamName());
	ThemeChangeInterceptor interceptor2 = (ThemeChangeInterceptor) chain.getInterceptors()[2];
	assertEquals("style", interceptor2.getParamName());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:MvcNamespaceTests.java

示例6: testContentNegotiationManager

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
@Test
public void testContentNegotiationManager() throws Exception {
	loadBeanDefinitions("mvc-config-content-negotiation-manager.xml", 15);

	RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
	ContentNegotiationManager manager = mapping.getContentNegotiationManager();

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.xml");
	NativeWebRequest webRequest = new ServletWebRequest(request);
	assertEquals(Arrays.asList(MediaType.valueOf("application/rss+xml")), manager.resolveMediaTypes(webRequest));

	ViewResolverComposite compositeResolver = this.appContext.getBean(ViewResolverComposite.class);
	assertNotNull(compositeResolver);
	assertEquals("Actual: " + compositeResolver.getViewResolvers(), 1, compositeResolver.getViewResolvers().size());

	ViewResolver resolver = compositeResolver.getViewResolvers().get(0);
	assertEquals(ContentNegotiatingViewResolver.class, resolver.getClass());
	ContentNegotiatingViewResolver cnvr = (ContentNegotiatingViewResolver) resolver;
	assertSame(manager, cnvr.getContentNegotiationManager());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:MvcNamespaceTests.java

示例7: testPathMatchingHandlerMappings

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
@Test
public void testPathMatchingHandlerMappings() throws Exception {
	loadBeanDefinitions("mvc-config-path-matching-mappings.xml", 23);

	RequestMappingHandlerMapping requestMapping = appContext.getBean(RequestMappingHandlerMapping.class);
	assertNotNull(requestMapping);
	assertEquals(TestPathHelper.class, requestMapping.getUrlPathHelper().getClass());
	assertEquals(TestPathMatcher.class, requestMapping.getPathMatcher().getClass());

	SimpleUrlHandlerMapping viewController = appContext.getBean(VIEWCONTROLLER_BEAN_NAME, SimpleUrlHandlerMapping.class);
	assertNotNull(viewController);
	assertEquals(TestPathHelper.class, viewController.getUrlPathHelper().getClass());
	assertEquals(TestPathMatcher.class, viewController.getPathMatcher().getClass());

	for (SimpleUrlHandlerMapping handlerMapping : appContext.getBeansOfType(SimpleUrlHandlerMapping.class).values()) {
		assertNotNull(handlerMapping);
		assertEquals(TestPathHelper.class, handlerMapping.getUrlPathHelper().getClass());
		assertEquals(TestPathMatcher.class, handlerMapping.getPathMatcher().getClass());
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:MvcNamespaceTests.java

示例8: requestMappingHandlerMapping

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
@Test
public void requestMappingHandlerMapping() throws Exception {
	ApplicationContext context = initContext(WebConfig.class, ScopedController.class, ScopedProxyController.class);
	RequestMappingHandlerMapping handlerMapping = context.getBean(RequestMappingHandlerMapping.class);
	assertEquals(0, handlerMapping.getOrder());

	HandlerExecutionChain chain = handlerMapping.getHandler(new MockHttpServletRequest("GET", "/"));
	assertNotNull(chain);
	assertNotNull(chain.getInterceptors());
	assertEquals(ConversionServiceExposingInterceptor.class, chain.getInterceptors()[0].getClass());

	chain = handlerMapping.getHandler(new MockHttpServletRequest("GET", "/scoped"));
	assertNotNull("HandlerExecutionChain for '/scoped' mapping should not be null.", chain);

	chain = handlerMapping.getHandler(new MockHttpServletRequest("GET", "/scopedProxy"));
	assertNotNull("HandlerExecutionChain for '/scopedProxy' mapping should not be null.", chain);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:WebMvcConfigurationSupportTests.java

示例9: suffixPatternMatch

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
@Test
public void suffixPatternMatch() throws Exception {
	TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PersonController());
	builder.setUseSuffixPatternMatch(false);
	builder.build();

	RequestMappingHandlerMapping hm = builder.wac.getBean(RequestMappingHandlerMapping.class);

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/persons");
	HandlerExecutionChain chain = hm.getHandler(request);
	assertNotNull(chain);
	assertEquals("persons", ((HandlerMethod) chain.getHandler()).getMethod().getName());

	request = new MockHttpServletRequest("GET", "/persons.xml");
	chain = hm.getHandler(request);
	assertNull(chain);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:StandaloneMockMvcBuilderTests.java

示例10: sitePreferenceHandlerInterceptorRegistered

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
@Test
public void sitePreferenceHandlerInterceptorRegistered() throws Exception {
	this.context = new AnnotationConfigWebApplicationContext();
	this.context.setServletContext(new MockServletContext());
	this.context.register(Config.class, WebMvcAutoConfiguration.class,
			HttpMessageConvertersAutoConfiguration.class,
			SitePreferenceAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	this.context.refresh();
	RequestMappingHandlerMapping mapping = this.context
			.getBean(RequestMappingHandlerMapping.class);
	HandlerInterceptor[] interceptors = mapping
			.getHandler(new MockHttpServletRequest()).getInterceptors();
	assertThat(interceptors)
			.hasAtLeastOneElementOfType(SitePreferenceHandlerInterceptor.class);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:SitePreferenceAutoConfigurationTests.java

示例11: webMvcRegistrations

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
@Bean
public WebMvcRegistrations webMvcRegistrations() {
	return new WebMvcRegistrationsAdapter() {
		@Override
		public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
			DefaultRequestMappingHandlerMapping mapping = new DefaultRequestMappingHandlerMapping();
			mapping.setControllerPostfix("Controller");
			mapping.setExcludePatterns(new String[]{
					"/js/**",
					"/css/**",
					"/imgs/**"
			});
			return mapping;
		}
		
		@Override
		public RequestMappingHandlerAdapter getRequestMappingHandlerAdapter() {
			DefaultRequestMappingHandlerAdapter adapter = new DefaultRequestMappingHandlerAdapter();
			adapter.setAutoView(true);
			return adapter;
		}
	};
}
 
开发者ID:easycodebox,项目名称:easycode,代码行数:24,代码来源:SpringMvcConfig.java

示例12: getHandlerExecution

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
protected HandlerExecutionChain getHandlerExecution(HttpServletRequest request) throws Exception {

		WebApplicationContext appContext = WebApplicationContextUtils
				.getRequiredWebApplicationContext(request.getServletContext());
		HandlerMapping bean = appContext.getBean(RequestMappingHandlerMapping.class);
		HandlerExecutionChain handler = bean.getHandler(request);

		if (handler == null) {
			ServletContext servletContext = request.getServletContext();
			Enumeration<?> attrNameEnum = servletContext.getAttributeNames();
			while (attrNameEnum.hasMoreElements()) {
				String attrName = (String) attrNameEnum.nextElement();
				if (attrName.startsWith(FrameworkServlet.SERVLET_CONTEXT_PREFIX)) {
					appContext = (WebApplicationContext) servletContext.getAttribute(attrName);
					bean = appContext.getBean(RequestMappingHandlerMapping.class);
					handler = bean.getHandler(request);
					if (handler != null) {
						break;
					}
				}
			}
		}

		return handler;
	}
 
开发者ID:KayuraTeam,项目名称:kayura-uasp,代码行数:26,代码来源:PrivilegeAuthenticationFilter.java

示例13: sitePreferenceHandlerInterceptorRegistered

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
@Test
public void sitePreferenceHandlerInterceptorRegistered() throws Exception {
	this.context = new AnnotationConfigWebApplicationContext();
	this.context.setServletContext(new MockServletContext());
	this.context.register(Config.class, WebMvcAutoConfiguration.class,
			HttpMessageConvertersAutoConfiguration.class,
			SitePreferenceAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	this.context.refresh();
	RequestMappingHandlerMapping mapping = this.context
			.getBean(RequestMappingHandlerMapping.class);
	HandlerInterceptor[] interceptors = mapping
			.getHandler(new MockHttpServletRequest()).getInterceptors();
	assertThat(interceptors,
			hasItemInArray(instanceOf(SitePreferenceHandlerInterceptor.class)));
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:17,代码来源:SitePreferenceAutoConfigurationTests.java

示例14: deviceResolverHandlerInterceptorRegistered

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
@Test
public void deviceResolverHandlerInterceptorRegistered() throws Exception {
	this.context = new AnnotationConfigWebApplicationContext();
	this.context.setServletContext(new MockServletContext());
	this.context.register(Config.class, WebMvcAutoConfiguration.class,
			HttpMessageConvertersAutoConfiguration.class,
			DeviceResolverAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	this.context.refresh();
	RequestMappingHandlerMapping mapping = this.context
			.getBean(RequestMappingHandlerMapping.class);
	HandlerInterceptor[] interceptors = mapping
			.getHandler(new MockHttpServletRequest()).getInterceptors();
	assertThat(interceptors,
			hasItemInArray(instanceOf(DeviceResolverHandlerInterceptor.class)));
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:17,代码来源:DeviceResolverAutoConfigurationTests.java

示例15: getRequestMappingHandlerMappingInfoMapForLog

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
/**
 * 获得 request mapping handler mapping info map for LOGGER.
 *
 * @param webApplicationContext
 *            the web application context
 * @return the request mapping handler mapping info map for log
 */
public static final Map<String, Object> getRequestMappingHandlerMappingInfoMapForLog(WebApplicationContext webApplicationContext){
    RequestMappingHandlerMapping requestMappingHandlerMapping = webApplicationContext.getBean(RequestMappingHandlerMapping.class);

    Map<String, Object> mappingInfoMap = newLinkedHashMap();

    mappingInfoMap.put("useRegisteredSuffixPatternMatch()", requestMappingHandlerMapping.useRegisteredSuffixPatternMatch());
    mappingInfoMap.put("useSuffixPatternMatch()", requestMappingHandlerMapping.useSuffixPatternMatch());
    mappingInfoMap.put("useTrailingSlashMatch()", requestMappingHandlerMapping.useTrailingSlashMatch());
    mappingInfoMap.put("getDefaultHandler()", requestMappingHandlerMapping.getDefaultHandler());
    mappingInfoMap.put("getFileExtensions()", requestMappingHandlerMapping.getFileExtensions());
    mappingInfoMap.put("getOrder()", requestMappingHandlerMapping.getOrder());
    mappingInfoMap.put("getPathMatcher()", requestMappingHandlerMapping.getPathMatcher());
    mappingInfoMap.put("getUrlPathHelper()", requestMappingHandlerMapping.getUrlPathHelper());

    //---------------------------------------------------------------
    Map<String, RequestMappingInfo> methodAndRequestMappingInfoMapMap = buildMethodAndRequestMappingInfoMap(
                    requestMappingHandlerMapping);
    mappingInfoMap.put("methodAndRequestMappingInfoMapMap", methodAndRequestMappingInfoMapMap);
    return mappingInfoMap;
}
 
开发者ID:venusdrogon,项目名称:feilong-spring,代码行数:28,代码来源:HandlerMappingUtil.java


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