本文整理了Java中org.springframework.web.servlet.ModelAndView.getViewName()
方法的一些代码示例,展示了ModelAndView.getViewName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ModelAndView.getViewName()
方法的具体详情如下:
包路径:org.springframework.web.servlet.ModelAndView
类名称:ModelAndView
方法名:getViewName
[英]Return the view name to be resolved by the DispatcherServlet via a ViewResolver, or null if we are using a View object.
[中]返回DispatcherServlet通过ViewResolver解析的视图名称,如果使用的是视图对象,则返回null。
代码示例来源:origin: spring-projects/spring-framework
/**
* Check to see if the view name in the ModelAndView matches the given
* {@code expectedName}.
* @param mav the ModelAndView to test against (never {@code null})
* @param expectedName the name of the model value
*/
public static void assertViewName(ModelAndView mav, String expectedName) {
assertTrue("View name is not equal to '" + expectedName + "' but was '" + mav.getViewName() + "'",
ObjectUtils.nullSafeEquals(expectedName, mav.getViewName()));
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Assert the selected view name.
*/
public ResultMatcher name(final String expectedViewName) {
return result -> {
ModelAndView mav = result.getModelAndView();
if (mav == null) {
fail("No ModelAndView found");
}
assertEquals("View name", expectedViewName, mav.getViewName());
};
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void threeMappings() {
Exception oddException = new AnotherOddException();
Properties props = new Properties();
props.setProperty("java.lang.Exception", "error");
props.setProperty("SomeOddException", "another-error");
props.setProperty("AnotherOddException", "another-some-error");
exceptionResolver.setMappedHandlers(Collections.singleton(handler1));
exceptionResolver.setExceptionMappings(props);
ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, oddException);
assertEquals("another-some-error", mav.getViewName());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void twoMappings() {
Properties props = new Properties();
props.setProperty("java.lang.Exception", "error");
props.setProperty("AnotherException", "another-error");
exceptionResolver.setMappedHandlers(Collections.singleton(handler1));
exceptionResolver.setExceptionMappings(props);
ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, genericException);
assertEquals("error", mav.getViewName());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void twoMappingsOneShortOneLong() {
Properties props = new Properties();
props.setProperty("Exception", "error");
props.setProperty("AnotherException", "another-error");
exceptionResolver.setMappedHandlers(Collections.singleton(handler1));
exceptionResolver.setExceptionMappings(props);
ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, genericException);
assertEquals("error", mav.getViewName());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void exactExceptionMappingWithHandlerSpecified() {
Properties props = new Properties();
props.setProperty("java.lang.Exception", "error");
exceptionResolver.setMappedHandlers(Collections.singleton(handler1));
exceptionResolver.setExceptionMappings(props);
ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, genericException);
assertEquals("error", mav.getViewName());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void exactExceptionMappingWithHandlerClassSpecified() {
Properties props = new Properties();
props.setProperty("java.lang.Exception", "error");
exceptionResolver.setMappedHandlerClasses(String.class);
exceptionResolver.setExceptionMappings(props);
ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, genericException);
assertEquals("error", mav.getViewName());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void exactExceptionMappingWithHandlerInterfaceSpecified() {
Properties props = new Properties();
props.setProperty("java.lang.Exception", "error");
exceptionResolver.setMappedHandlerClasses(Comparable.class);
exceptionResolver.setExceptionMappings(props);
ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, genericException);
assertEquals("error", mav.getViewName());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void viewName() throws Exception {
this.controller.setViewName("view");
ModelAndView modelAndView = this.controller.handleRequest(this.request, this.response);
assertEquals("view", modelAndView.getViewName());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void defaultErrorView() {
exceptionResolver.setDefaultErrorView("default-view");
ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, genericException);
assertEquals("default-view", mav.getViewName());
assertEquals(genericException, mav.getModel().get(SimpleMappingExceptionResolver.DEFAULT_EXCEPTION_ATTRIBUTE));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void handleRequestWithoutViewName() throws Exception {
ModelAndView mav = this.controller.handleRequest(this.request, new MockHttpServletResponse());
assertNull(mav.getViewName());
assertTrue(mav.getModel().isEmpty());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void parameterizableViewController() throws Exception {
String viewName = "viewName";
ParameterizableViewController pvc = new ParameterizableViewController();
pvc.setViewName(viewName);
// We don't care about the params.
ModelAndView mv = pvc.handleRequest(new MockHttpServletRequest("GET", "foo.html"), new MockHttpServletResponse());
assertTrue("model has no data", mv.getModel().size() == 0);
assertTrue("model has correct viewname", mv.getViewName().equals(viewName));
assertTrue("getViewName matches", pvc.getViewName().equals(viewName));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void nullExceptionMappings() {
exceptionResolver.setExceptionMappings(null);
exceptionResolver.setDefaultErrorView("default-view");
ModelAndView mav = exceptionResolver.resolveException(request, response, handler1, genericException);
assertEquals("default-view", mav.getViewName());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void handleRequestWithViewName() throws Exception {
String viewName = "testView";
this.controller.setViewName(viewName);
ModelAndView mav = this.controller.handleRequest(this.request, new MockHttpServletResponse());
assertEquals(viewName, mav.getViewName());
assertTrue(mav.getModel().isEmpty());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void withPlainFilename() throws Exception {
UrlFilenameViewController ctrl = new UrlFilenameViewController();
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/index");
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView mv = ctrl.handleRequest(request, response);
assertEquals("index", mv.getViewName());
assertTrue(mv.getModel().isEmpty());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void withFilenamePlusExtension() throws Exception {
UrlFilenameViewController ctrl = new UrlFilenameViewController();
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/index.html");
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView mv = ctrl.handleRequest(request, response);
assertEquals("index", mv.getViewName());
assertTrue(mv.getModel().isEmpty());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void multiLevel() throws Exception {
UrlFilenameViewController ctrl = new UrlFilenameViewController();
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/docs/cvs/commit.html");
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView mv = ctrl.handleRequest(request, response);
assertEquals("docs/cvs/commit", mv.getViewName());
assertTrue(mv.getModel().isEmpty());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void resolveExceptionModelAndView() throws NoSuchMethodException {
IllegalArgumentException ex = new IllegalArgumentException("Bad argument");
HandlerMethod handlerMethod = new HandlerMethod(new ModelAndViewController(), "handle");
this.resolver.afterPropertiesSet();
ModelAndView mav = this.resolver.resolveException(this.request, this.response, handlerMethod, ex);
assertNotNull(mav);
assertFalse(mav.isEmpty());
assertEquals("errorView", mav.getViewName());
assertEquals("Bad argument", mav.getModel().get("detail"));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void multiLevelMappingWithFallback() throws Exception {
UrlFilenameViewController ctrl = new UrlFilenameViewController();
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/docs/cvs/commit.html");
exposePathInMapping(request, "/docs/cvs/commit.html");
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView mv = ctrl.handleRequest(request, response);
assertEquals("docs/cvs/commit", mv.getViewName());
assertTrue(mv.getModel().isEmpty());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void withPrefixAndSuffix() throws Exception {
UrlFilenameViewController ctrl = new UrlFilenameViewController();
ctrl.setPrefix("mypre_");
ctrl.setSuffix("_mysuf");
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/index.html");
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView mv = ctrl.handleRequest(request, response);
assertEquals("mypre_index_mysuf", mv.getViewName());
assertTrue(mv.getModel().isEmpty());
}
内容来源于网络,如有侵权,请联系作者删除!