0

I coded a wee login controller. It has an onSubmit method which logs in the user. If the login is successful I want to show the front page without having to redirect. The front page needs content from some other model. Because my LoginController already has a LoginModel it can't also have the InformationModel.

Is there some way to get a pointer on the InformationModel? Or some call to get the ModelAndView of the InformationController? That controller provides a handleRequest method.

I think this is more a fundamental question, but if you need code to answer it I will supply it.

4

1 回答 1

2

我不确定我是否正确地回答了你的问题,但是

a.) 您可以在 ModelAndView 对象上添加多个模型。利用:

 modelAndView.addObject("informationModel", informationModelObject);

b.) 如果登录成功,将视图设置为您的首页视图:

 modelAndView.setView("frontPageView");

要在 LoginController 上访问 InformationController,您可以自动装配它 =)

@Autowired
InformationController informationController;

    @RequestMapping( ... ) // assuming you define it here
    public ModelAndView onSubmit(... ) {
      // .. code here

      if (loginsuccess) {
          InformationModel informationModelObject = informationController.handleRequest(...);
           modelAndView.addObject("informationModel", informationModelObject);
          modelAndView.setView("frontPageView");
      }
      else {
         modelAndView.setView("loginFailView");
      }

      return modelAndView;
    }
于 2011-06-05T16:27:52.540 回答