1

I have a spring MVC application and I want to call from a controller a method that requires a ModelAndView as attribute. In my controller method I have the Model. I can't change my controller to use ModelAndView instead of Model and I can't change the signature of the method I want to call.

Can I somehow convert the Model to an equivalent ModelAndView?

DianaM
  • 257
  • 4
  • 11
  • Hello Diana you got confused with the framework .Model is your pojo class and model view is Model+view I.e it will bind your pojo to your view.You can add the model to your modelview object but you cannot convert it.You can get the model out of mode view .I think this would suffice you.Also ping the code nippet – Pradeep Apr 06 '17 at 15:57

1 Answers1

2

If view is not important, than:

ModelAndView view = new ModelAndView();
view.addAllObjects(model.asMap());
ZhenyaM
  • 676
  • 1
  • 5
  • 15