LoginFormController-->Post 在表单提交/发布后调用。最后,它调用另一个名为 LandingFormController-->loadForm 的控制器。
好吧,在 loadForm 中,模型中的值似乎是空的。有没有办法可以在会话或请求中保留一个 Bean 并在 loadForm 方法中获取它?奖励积分:如果您可以指出一些文件以供参考:)
谢谢
@Controller
@RequestMapping(value="/login")
public class LoginFormController {
@RequestMapping(method=RequestMethod.POST)
public ModelAndView post(@ModelAttribute User user, BindingResult result, SessionStatus status) {
logger.info("post");
new ReceiptUserValidator().validate(user, result);
if (result.hasErrors()) {
return new ModelAndView("login");
}
else {
logger.info("Email Id: " + user.getEmailId());
//status.setComplete();
Map<String, Object> model = new HashMap<String, Object>();
model.put("userId", user.getEmailId());
model.put("now", new Date().toString());
return new ModelAndView("redirect:/landing.htm", "model", model);
}
}
下面的控制器 B 被调用
@Controller
@RequestMapping(value="/landing")
public class LandingFormController {
protected final Log logger = LogFactory.getLog(getClass());
@RequestMapping(method=RequestMethod.GET)
public String loadForm(Model model) {
logger.info("LandingFormController loadForm: " + model.asMap().keySet());
return "landing";
}
}