I seen some Spring MVC controller code with parameter of the type Model. I have used spring controller but never used parameter of type Model. What is this parameter of type model in spring controller method for. Is it mandatory(I do not thing so as I have never used it and still run spring MVC code).
dou you know the meaning of "mvc"? Model, View Controller. Look this up on google and read about it. In short, it's a design pattern that aims to separate different types of logic into their own components to simply coding as well as to improve code reuse.
The model is the "thing" that contains your data and your business logic. The model is also used as a means to store data that should later be displayed in the view (UI). So in the controller, store the data to be displayed into the view, which in spring mvc, as far as I remember
is just something like a simple map. In the view, you can then later access this model to display it - this is a way to decouple your controller from the view.
I am aware of MVC and have worked on MVC frameworks like Struts,Spring MVC. I know that model is used to store data but I have known model in model view controller as a concept but not as a keyword or type. Even if we are not having a parameter of type model in spring controller method, still it functions as MVC as the concept of model is used there. My doubt is regarding model the keyword,the type rather than model the concept.
I will explain the doubt with an example.In the below code there is model of type ModelMap in the parameter of spring controller method but is is not used at all. Without it , the code still works fine.
Returning String object and passing data through ModelMap is a newer approach in Spring, this approach will be familiar for people coming from struts background.
This said, it does not mean newer approach is better, hardly there are any difference.
posted 5 years ago
thanks. In my code since I am not using the ModelMap at all and rather the modelandview parameter, let me try to remove the parameter and check.
Morning came much too soon and it brought along a friend named Margarita Hangover, and a tiny ad.