本文整理汇总了Java中org.springframework.web.servlet.mvc.ParameterizableViewController类的典型用法代码示例。如果您正苦于以下问题:Java ParameterizableViewController类的具体用法?Java ParameterizableViewController怎么用?Java ParameterizableViewController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParameterizableViewController类属于org.springframework.web.servlet.mvc包,在下文中一共展示了ParameterizableViewController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rootController
import org.springframework.web.servlet.mvc.ParameterizableViewController; //导入依赖的package包/类
@Bean
protected Controller rootController() {
return new ParameterizableViewController() {
@Override
protected ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response)
throws Exception {
final String queryString = request.getQueryString();
final String url = request.getContextPath() + "/login" + (queryString != null ? '?' + queryString : StringUtils.EMPTY);
return new ModelAndView(new RedirectView(response.encodeURL(url)));
}
};
}
示例2: testViewControllersDefaultConfig
import org.springframework.web.servlet.mvc.ParameterizableViewController; //导入依赖的package包/类
@Test
public void testViewControllersDefaultConfig() {
loadBeanDefinitions("mvc-config-view-controllers-minimal.xml", 7);
SimpleUrlHandlerMapping hm = this.appContext.getBean(SimpleUrlHandlerMapping.class);
assertNotNull(hm);
ParameterizableViewController viewController = (ParameterizableViewController) hm.getUrlMap().get("/path");
assertNotNull(viewController);
assertEquals("home", viewController.getViewName());
ParameterizableViewController redirectViewController = (ParameterizableViewController) hm.getUrlMap().get("/old");
assertNotNull(redirectViewController);
assertThat(redirectViewController.getView(), Matchers.instanceOf(RedirectView.class));
ParameterizableViewController statusViewController = (ParameterizableViewController) hm.getUrlMap().get("/bad");
assertNotNull(statusViewController);
assertEquals(404, statusViewController.getStatusCode().value());
BeanNameUrlHandlerMapping beanNameMapping = this.appContext.getBean(BeanNameUrlHandlerMapping.class);
assertNotNull(beanNameMapping);
assertEquals(2, beanNameMapping.getOrder());
}
示例3: rootController
import org.springframework.web.servlet.mvc.ParameterizableViewController; //导入依赖的package包/类
@Bean
protected Controller rootController() {
return new ParameterizableViewController() {
@Override
protected ModelAndView handleRequestInternal(final HttpServletRequest request,
final HttpServletResponse response)
throws Exception {
final String queryString = request.getQueryString();
final String url = request.getContextPath() + "/login"
+ (queryString != null ? '?' + queryString : StringUtils.EMPTY);
return new ModelAndView(new RedirectView(response.encodeURL(url)));
}
};
}
示例4: rootController
import org.springframework.web.servlet.mvc.ParameterizableViewController; //导入依赖的package包/类
@Bean
protected Controller rootController() {
return new ParameterizableViewController() {
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
String queryString = request.getQueryString();
String url = request.getContextPath() + "/login" + (queryString != null ? '?' + queryString : "");
return new ModelAndView(new RedirectView(response.encodeURL(url)));
}
};
}
示例5: addViewController
import org.springframework.web.servlet.mvc.ParameterizableViewController; //导入依赖的package包/类
@Test
public void addViewController() {
this.registry.addViewController("/path").setViewName("viewName");
ParameterizableViewController controller = getController("/path");
assertEquals("viewName", controller.getViewName());
assertNull(controller.getStatusCode());
assertFalse(controller.isStatusOnly());
assertNotNull(controller.getApplicationContext());
}
示例6: addViewControllerWithDefaultViewName
import org.springframework.web.servlet.mvc.ParameterizableViewController; //导入依赖的package包/类
@Test
public void addViewControllerWithDefaultViewName() {
this.registry.addViewController("/path");
ParameterizableViewController controller = getController("/path");
assertNull(controller.getViewName());
assertNull(controller.getStatusCode());
assertFalse(controller.isStatusOnly());
assertNotNull(controller.getApplicationContext());
}
示例7: addStatusController
import org.springframework.web.servlet.mvc.ParameterizableViewController; //导入依赖的package包/类
@Test
public void addStatusController() {
this.registry.addStatusController("/path", HttpStatus.NOT_FOUND);
ParameterizableViewController controller = getController("/path");
assertNull(controller.getViewName());
assertEquals(HttpStatus.NOT_FOUND, controller.getStatusCode());
assertTrue(controller.isStatusOnly());
assertNotNull(controller.getApplicationContext());
}
示例8: getRedirectView
import org.springframework.web.servlet.mvc.ParameterizableViewController; //导入依赖的package包/类
private RedirectView getRedirectView(String path) {
ParameterizableViewController controller = getController(path);
assertNull(controller.getViewName());
assertNotNull(controller.getView());
assertEquals(RedirectView.class, controller.getView().getClass());
return (RedirectView) controller.getView();
}
示例9: WelcomePageHandlerMapping
import org.springframework.web.servlet.mvc.ParameterizableViewController; //导入依赖的package包/类
WelcomePageHandlerMapping(Collection<String> paths) {
ParameterizableViewController controller = new ParameterizableViewController();
controller.setViewName("forward:" + target);
paths.forEach(path -> registerHandler(path, controller));
//we handle only non handled resources, but resource handler (which has LOWEST_PRECEDENCE - 1) handle all
setOrder(LOWEST_PRECEDENCE - 10);
}
示例10: parse
import org.springframework.web.servlet.mvc.ParameterizableViewController; //导入依赖的package包/类
public BeanDefinition parse(Element element, ParserContext parserContext) {
Object source = parserContext.extractSource(element);
// Register SimpleUrlHandlerMapping for view controllers
BeanDefinition handlerMappingDef = registerHandlerMapping(parserContext, source);
// Ensure BeanNameUrlHandlerMapping (SPR-8289) and default HandlerAdapters are not "turned off"
MvcNamespaceUtils.registerDefaultComponents(parserContext, source);
// Create view controller bean definition
RootBeanDefinition viewControllerDef = new RootBeanDefinition(ParameterizableViewController.class);
viewControllerDef.setSource(source);
if (element.hasAttribute("view-name")) {
viewControllerDef.getPropertyValues().add("viewName", element.getAttribute("view-name"));
}
Map<String, BeanDefinition> urlMap;
if (handlerMappingDef.getPropertyValues().contains("urlMap")) {
urlMap = (Map<String, BeanDefinition>) handlerMappingDef.getPropertyValues().getPropertyValue("urlMap").getValue();
}
else {
urlMap = new ManagedMap<String, BeanDefinition>();
handlerMappingDef.getPropertyValues().add("urlMap", urlMap);
}
urlMap.put(element.getAttribute("path"), viewControllerDef);
return null;
}
示例11: addViewController
import org.springframework.web.servlet.mvc.ParameterizableViewController; //导入依赖的package包/类
@Test
public void addViewController() {
registry.addViewController("/path");
Map<String, ?> urlMap = getHandlerMapping().getUrlMap();
ParameterizableViewController controller = (ParameterizableViewController) urlMap.get("/path");
assertNotNull(controller);
assertNull(controller.getViewName());
}
示例12: addViewControllerWithViewName
import org.springframework.web.servlet.mvc.ParameterizableViewController; //导入依赖的package包/类
@Test
public void addViewControllerWithViewName() {
registry.addViewController("/path").setViewName("viewName");
Map<String, ?> urlMap = getHandlerMapping().getUrlMap();
ParameterizableViewController controller = (ParameterizableViewController) urlMap.get("/path");
assertNotNull(controller);
assertEquals("viewName", controller.getViewName());
}
示例13: getViewController
import org.springframework.web.servlet.mvc.ParameterizableViewController; //导入依赖的package包/类
protected ParameterizableViewController getViewController() {
return this.controller;
}
示例14: parse
import org.springframework.web.servlet.mvc.ParameterizableViewController; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public BeanDefinition parse(Element element, ParserContext parserContext) {
Object source = parserContext.extractSource(element);
// Register SimpleUrlHandlerMapping for view controllers
BeanDefinition hm = registerHandlerMapping(parserContext, source);
// Ensure BeanNameUrlHandlerMapping (SPR-8289) and default HandlerAdapters are not "turned off"
MvcNamespaceUtils.registerDefaultComponents(parserContext, source);
// Create view controller bean definition
RootBeanDefinition controller = new RootBeanDefinition(ParameterizableViewController.class);
controller.setSource(source);
HttpStatus statusCode = null;
if (element.hasAttribute("status-code")) {
int statusValue = Integer.valueOf(element.getAttribute("status-code"));
statusCode = HttpStatus.valueOf(statusValue);
}
String name = element.getLocalName();
if (name.equals("view-controller")) {
if (element.hasAttribute("view-name")) {
controller.getPropertyValues().add("viewName", element.getAttribute("view-name"));
}
if (statusCode != null) {
controller.getPropertyValues().add("statusCode", statusCode);
}
}
else if (name.equals("redirect-view-controller")) {
controller.getPropertyValues().add("view", getRedirectView(element, statusCode, source));
}
else if (name.equals("status-controller")) {
controller.getPropertyValues().add("statusCode", statusCode);
controller.getPropertyValues().add("statusOnly", true);
}
else {
// Should never happen...
throw new IllegalStateException("Unexpected tag name: " + name);
}
Map<String, BeanDefinition> urlMap;
if (hm.getPropertyValues().contains("urlMap")) {
urlMap = (Map<String, BeanDefinition>) hm.getPropertyValues().getPropertyValue("urlMap").getValue();
}
else {
urlMap = new ManagedMap<String, BeanDefinition>();
hm.getPropertyValues().add("urlMap", urlMap);
}
urlMap.put(element.getAttribute("path"), controller);
return null;
}
示例15: setUp
import org.springframework.web.servlet.mvc.ParameterizableViewController; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
this.controller = new ParameterizableViewController();
this.request = new MockHttpServletRequest("GET", "/");
this.response = new MockHttpServletResponse();
}