本文整理汇总了Java中org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap类的典型用法代码示例。如果您正苦于以下问题:Java RedirectAttributesModelMap类的具体用法?Java RedirectAttributesModelMap怎么用?Java RedirectAttributesModelMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RedirectAttributesModelMap类属于org.springframework.web.servlet.mvc.support包,在下文中一共展示了RedirectAttributesModelMap类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:sdl,项目名称:dxa-modules,代码行数:17,代码来源:AudienceControllerTest.java
示例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);
}
开发者ID:sdl,项目名称:dxa-modules,代码行数:18,代码来源:AudienceControllerTest.java
示例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);
}
开发者ID:alfio-event,项目名称:alf.io,代码行数:17,代码来源:ReservationFlowIntegrationTest.java
示例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());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:ViewNameMethodReturnValueHandlerTests.java
示例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());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:ViewNameMethodReturnValueHandlerTests.java
示例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());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:ViewNameMethodReturnValueHandlerTests.java
示例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());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:12,代码来源:ViewMethodReturnValueHandlerTests.java
示例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);
}
开发者ID:sdl,项目名称:dxa-modules,代码行数:15,代码来源:AudienceControllerTest.java
示例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;
}
开发者ID:deathspeeder,项目名称:class-guard,代码行数:11,代码来源:RedirectAttributesMethodArgumentResolver.java
示例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());
}
开发者ID:deathspeeder,项目名称:class-guard,代码行数:11,代码来源:ViewNameMethodReturnValueHandlerTests.java
示例16: handleRedirectAttributesWithViewInstance
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap; //导入依赖的package包/类
@Test
public void handleRedirectAttributesWithViewInstance() 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 should be used if controller redirects", redirectAttributes, model);
}
开发者ID:deathspeeder,项目名称:class-guard,代码行数:14,代码来源:ModelAndViewMethodReturnValueHandlerTests.java
示例17: payOffline
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap; //导入依赖的package包/类
private String payOffline(String eventName, String reservationIdentifier) {
PaymentForm paymentForm = new PaymentForm();
paymentForm.setPaymentMethod(PaymentProxy.OFFLINE);
paymentForm.setEmail("[email protected]");
paymentForm.setBillingAddress("my billing address");
paymentForm.setFirstName("full");
paymentForm.setLastName("name");
paymentForm.setTermAndConditionsAccepted(true);
paymentForm.setPostponeAssignment(true);
BindingResult bindingResult = new BeanPropertyBindingResult(paymentForm, "paymentForm");
Model model = new BindingAwareModelMap();
MockHttpServletRequest request = new MockHttpServletRequest();
RedirectAttributes redirectAttributes = new RedirectAttributesModelMap();
return reservationController.handleReservation(eventName, reservationIdentifier, paymentForm, bindingResult, model, request, Locale.ENGLISH, redirectAttributes);
}
开发者ID:alfio-event,项目名称:alf.io,代码行数:16,代码来源:ReservationFlowIntegrationTest.java
示例18: saveUpload
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap; //导入依赖的package包/类
@RequiresUser
@RequestMapping(value = "/save", method = RequestMethod.POST)
public String saveUpload(@RequestParam(value = "file", required = true) MultipartFile file,
@RequestParam(value = "privateFile", required = false, defaultValue = "false") final boolean privateFile,
@RequestParam(value = "description", required = false, defaultValue = "") final String description,
RedirectAttributesModelMap redirectAttributesModelMap) throws Exception {
//
final String creator = SecurityUtils2.getUsername();
//
if (file.isEmpty()) {
throw new Exception("PLEASE SELECT A FILE.");
} else {
Closer closer = Closer.create();
try {
final String mime = file.getContentType();
final String name = file.getOriginalFilename();
//
InputStream in = file.getInputStream();
closer.register(in);
//
Optional<FileEntry> fe = fileStoreService.save(name, mime, creator, privateFile, description, in);
if (fe.isPresent() == false) {
throw new Exception("FILE SAVE FAILED?!");
}
// flashmap-alert.
flashAlerts.add(redirectAttributesModelMap, new FlashAlerts.FlashAlert(BootstrapAlertTypes.INFO, "File Saved."));
//
return String.format("redirect:./info/%s", fe.get().getId());
} finally {
closer.close();
}
}
}
开发者ID:ageldama,项目名称:glados-wiki,代码行数:34,代码来源:FileController.java
示例19: savePage
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap; //导入依赖的package包/类
@RequiresUser
@RequestMapping(value = "/post", method = {RequestMethod.POST})
public View savePage(RedirectAttributesModelMap redirectAttributesModelMap,
@RequestParam(value = "title", required = true) final String title,
@RequestParam(value = "content", required = true) final String content,
@RequestParam(value = "aclForEveryone", required = false, defaultValue = "") final String aclForEveryone,
@RequestParam(value = "aclRUser", required = false) List<String> aclRUser,
@RequestParam(value = "aclWUser", required = false) List<String> aclWUser,
@RequestParam(value = "aclRGroup", required = false) List<String> aclRGroup,
@RequestParam(value = "aclWGroup", required = false) List<String> aclWGroup,
@RequestParam(value = "tag", required = false) List<String> tags,
@RequestParam(value = "origVersion", defaultValue = "", required = false) final String origVersion
)
throws Exception {
//
boolean jumped = false;
PageContent pageContentParent = null;
Page p = null;
if (pageService.existsByTitle(title)) {
p = pageService.getPageByTitle(title).get();
// check-acl
pageAclService.checkWritable(p);
//
ObjectId origVersion_ = new ObjectId(origVersion);
if (false == p.getCurrent().getId().equals(origVersion_)) {
jumped = true;
flashAlerts.add(redirectAttributesModelMap, new FlashAlerts.FlashAlert(BootstrapAlertTypes.WARNING, "Page Content has JUMPED! (maybe there's unmerged changes, check page versions.)"));
Optional<PageContent> pageContentParent_ = pageContentService.load(origVersion_);
if (pageContentParent_.isPresent()) {
pageContentParent = pageContentParent_.get();
} else {
LOG.warn(String.format("MISSING PARENT!!! -- parent=[%s], SKIP.", origVersion_.toString()));
}
} else {
pageContentParent = p.getCurrent();
}
} else {
// check-acl
pageAclService.checkWritable(null);
//
p = pageService.createByTitle(title);
}
//
PageContent pageContent = new PageContent();
pageContent.setContent(content);
pageContent.setCtime(new Date());
pageContent.setPage(p);
if (pageContentParent != null) {
pageContent.setParent(pageContentParent);
}
Optional<User> u = SecurityUtils2.getUser(userService);
if (u.isPresent()) {
pageContent.setCreator(u.get());
}
//
WikiSignatureExpandFunction wikiSignatureExpandFunction = new WikiSignatureExpandFunction(timeZoneService, u);
pageContent.setContent(wikiSignatureExpandFunction.apply(pageContent.getContent()));
//
pageContentService.save(pageContent);
//
pageService.addContent(pageContent);
p.setCurrent(pageContent);
//
p.setAclForEveryone(aclForEveryone);
p.setReadables(gatherUserAuthentications(aclRGroup, aclRUser));
p.setWritables(gatherUserAuthentications(aclWGroup, aclWUser));
setPageTags(p, tags);
//
pageService.update(p);
//
return redirectHelper.redirectToPageView(title);
}
开发者ID:ageldama,项目名称:glados-wiki,代码行数:73,代码来源:PageController.java
示例20: unauthenticated
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap; //导入依赖的package包/类
@RequestMapping(value = "/unauthenticated")
public RedirectView unauthenticated(RedirectAttributesModelMap redirectAttributesModelMap) {
flashAlerts.add(redirectAttributesModelMap, new FlashAlerts.FlashAlert(BootstrapAlertTypes.DANGER, "Unauthenticated!"));
return new RedirectView(String.format("%s/a/user/loginForm", WebappPath.getWebappPath()));
}
开发者ID:ageldama,项目名称:glados-wiki,代码行数:6,代码来源:ErrorController.java
注:本文中的org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论