本文整理汇总了Java中org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap类的典型用法代码示例。如果您正苦于以下问题:Java RedirectAttributesModelMap类的具体用法?Java RedirectAttributesModelMap怎么用?Java RedirectAttributesModelMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RedirectAttributesModelMap类属于org.springframework.web.servlet.mvc.support包,在下文中一共展示了RedirectAttributesModelMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldFailIfLoginFormIsNotValid
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap; //导入依赖的package包/类
@Test
public void shouldFailIfLoginFormIsNotValid() {
//given
RedirectAttributesModelMap map = new RedirectAttributesModelMap();
MapBindingResult bindingResult = new MapBindingResult(new HashMap<String, Object>(), "loginForm");
bindingResult.addError(new FieldError("test", "test", "test"));
LoginForm loginForm = new LoginForm();
loginForm.setLoginFormUrl("url");
//when
String path = controller.login(loginForm, bindingResult, map, new MockHttpServletRequest(), new MockHttpServletResponse());
//then
assertEquals(bindingResult.getAllErrors(), map.getFlashAttributes().get("errors"));
assertEquals("redirect:url", path);
}
示例2: shouldFailRequestIfCannotLogin
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap; //导入依赖的package包/类
@Test
public void shouldFailRequestIfCannotLogin() {
//given
RedirectAttributesModelMap map = new RedirectAttributesModelMap();
MapBindingResult bindingResult = new MapBindingResult(new HashMap<String, Object>(), "loginForm");
LoginForm loginForm = new LoginForm();
when(securityProvider.validate(any(LoginForm.class), any(HttpServletRequest.class), any(HttpServletResponse.class))).thenReturn(false);
//when
controller.login(loginForm, bindingResult, map, new MockHttpServletRequest(), new MockHttpServletResponse());
//then
assertTrue(map.getFlashAttributes().containsKey("errors"));
List<ObjectError> errors = (List<ObjectError>) map.getFlashAttributes().get("errors");
assertEquals("login.failed", errors.get(0).getCode());
assertTrue(errors.size() == 1);
}
示例3: reserveTicket
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap; //导入依赖的package包/类
private String reserveTicket(String eventName) {
ReservationForm reservationForm = new ReservationForm();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
ServletWebRequest servletWebRequest = new ServletWebRequest(request);
BindingResult bindingResult = new BeanPropertyBindingResult(reservationForm, "reservation");
Model model = new BindingAwareModelMap();
RedirectAttributes redirectAttributes = new RedirectAttributesModelMap();
TicketReservationModification ticketReservation = new TicketReservationModification();
ticketReservation.setAmount(1);
ticketReservation.setTicketCategoryId(ticketCategoryRepository.findByEventId(event.getId()).stream().findFirst().map(TicketCategory::getId).orElseThrow(IllegalStateException::new));
reservationForm.setReservation(Collections.singletonList(ticketReservation));
return eventController.reserveTicket(eventName, reservationForm, bindingResult, model, servletWebRequest, redirectAttributes, Locale.ENGLISH);
}
示例4: resolveArgument
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap; //导入依赖的package包/类
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
DataBinder dataBinder = binderFactory.createBinder(webRequest, null, null);
ModelMap redirectAttributes = new RedirectAttributesModelMap(dataBinder);
mavContainer.setRedirectModel(redirectAttributes);
return redirectAttributes;
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:RedirectAttributesMethodArgumentResolver.java
示例5: returnViewNameRedirect
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap; //导入依赖的package包/类
@Test
public void returnViewNameRedirect() throws Exception {
ModelMap redirectModel = new RedirectAttributesModelMap();
this.mavContainer.setRedirectModel(redirectModel);
this.handler.handleReturnValue("redirect:testView", this.param, this.mavContainer, this.webRequest);
assertEquals("redirect:testView", this.mavContainer.getViewName());
assertSame(redirectModel, this.mavContainer.getModel());
}
示例6: returnViewCustomRedirect
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap; //导入依赖的package包/类
@Test
public void returnViewCustomRedirect() throws Exception {
ModelMap redirectModel = new RedirectAttributesModelMap();
this.mavContainer.setRedirectModel(redirectModel);
this.handler.setRedirectPatterns("myRedirect:*");
this.handler.handleReturnValue("myRedirect:testView", this.param, this.mavContainer, this.webRequest);
assertEquals("myRedirect:testView", this.mavContainer.getViewName());
assertSame(redirectModel, this.mavContainer.getModel());
}
示例7: returnViewRedirectWithCustomRedirectPattern
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap; //导入依赖的package包/类
@Test
public void returnViewRedirectWithCustomRedirectPattern() throws Exception {
ModelMap redirectModel = new RedirectAttributesModelMap();
this.mavContainer.setRedirectModel(redirectModel);
this.handler.setRedirectPatterns("myRedirect:*");
this.handler.handleReturnValue("redirect:testView", this.param, this.mavContainer, this.webRequest);
assertEquals("redirect:testView", this.mavContainer.getViewName());
assertSame(redirectModel, this.mavContainer.getModel());
}
示例8: handleRedirectAttributesWithViewReference
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap; //导入依赖的package包/类
@Test
public void handleRedirectAttributesWithViewReference() throws Exception {
RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
mavContainer.setRedirectModel(redirectAttributes);
ModelAndView mav = new ModelAndView(new RedirectView(), "attrName", "attrValue");
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
assertEquals(RedirectView.class, mavContainer.getView().getClass());
assertEquals("attrValue", mavContainer.getModel().get("attrName"));
assertSame("RedirectAttributes should be used if controller redirects", redirectAttributes,
mavContainer.getModel());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:ModelAndViewMethodReturnValueHandlerTests.java
示例9: handleRedirectAttributesWithViewName
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap; //导入依赖的package包/类
@Test
public void handleRedirectAttributesWithViewName() throws Exception {
RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
mavContainer.setRedirectModel(redirectAttributes);
ModelAndView mav = new ModelAndView("redirect:viewName", "attrName", "attrValue");
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
ModelMap model = mavContainer.getModel();
assertEquals("redirect:viewName", mavContainer.getViewName());
assertEquals("attrValue", model.get("attrName"));
assertSame(redirectAttributes, model);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:ModelAndViewMethodReturnValueHandlerTests.java
示例10: handleRedirectAttributesWithCustomPrefix
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap; //导入依赖的package包/类
@Test
public void handleRedirectAttributesWithCustomPrefix() throws Exception {
RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
mavContainer.setRedirectModel(redirectAttributes);
ModelAndView mav = new ModelAndView("myRedirect:viewName", "attrName", "attrValue");
handler.setRedirectPatterns("myRedirect:*");
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
ModelMap model = mavContainer.getModel();
assertEquals("myRedirect:viewName", mavContainer.getViewName());
assertEquals("attrValue", model.get("attrName"));
assertSame(redirectAttributes, model);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:15,代码来源:ModelAndViewMethodReturnValueHandlerTests.java
示例11: handleRedirectAttributesWithoutRedirect
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap; //导入依赖的package包/类
@Test
public void handleRedirectAttributesWithoutRedirect() throws Exception {
RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
mavContainer.setRedirectModel(redirectAttributes);
ModelAndView mav = new ModelAndView();
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
ModelMap model = mavContainer.getModel();
assertEquals(null, mavContainer.getView());
assertTrue(mavContainer.getModel().isEmpty());
assertNotSame("RedirectAttributes should not be used if controller doesn't redirect", redirectAttributes, model);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:ModelAndViewMethodReturnValueHandlerTests.java
示例12: returnViewRedirect
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap; //导入依赖的package包/类
@Test
public void returnViewRedirect() throws Exception {
RedirectView redirectView = new RedirectView("testView");
ModelMap redirectModel = new RedirectAttributesModelMap();
this.mavContainer.setRedirectModel(redirectModel);
MethodParameter param = createReturnValueParam("view");
this.handler.handleReturnValue(redirectView, param, this.mavContainer, this.webRequest);
assertSame(redirectView, this.mavContainer.getView());
assertSame("Should have switched to the RedirectModel", redirectModel, this.mavContainer.getModel());
}
示例13: shouldLoginSuccessfullyAndRedirect
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap; //导入依赖的package包/类
@Test
public void shouldLoginSuccessfullyAndRedirect() {
//given
LoginForm form = new LoginForm();
RedirectAttributesModelMap map = new RedirectAttributesModelMap();
MapBindingResult bindingResult = new MapBindingResult(new HashMap<String, Object>(), "loginForm");
doReturn(true).when(securityProvider).validate(eq(form), any(HttpServletRequest.class), any(HttpServletResponse.class));
//when
String path = controller.login(form, bindingResult, map, new MockHttpServletRequest(), new MockHttpServletResponse());
//then
assertEquals("redirect:path", path);
}
示例14: resolveArgument
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap; //导入依赖的package包/类
public Object resolveArgument(
MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
throws Exception {
DataBinder dataBinder = binderFactory.createBinder(webRequest, null, null);
ModelMap redirectAttributes = new RedirectAttributesModelMap(dataBinder);
mavContainer.setRedirectModel(redirectAttributes);
return redirectAttributes;
}
示例15: returnViewNameRedirect
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap; //导入依赖的package包/类
@Test
public void returnViewNameRedirect() throws Exception {
ModelMap redirectModel = new RedirectAttributesModelMap();
this.mavContainer.setRedirectModel(redirectModel);
MethodParameter param = createReturnValueParam("viewName");
this.handler.handleReturnValue("redirect:testView", param, this.mavContainer, this.webRequest);
assertEquals("redirect:testView", this.mavContainer.getViewName());
assertSame("Should have switched to the RedirectModel", redirectModel, this.mavContainer.getModel());
}