在stackoverflow中看到一个很不错的解释,我先把原文粘到这里,下边我再翻译一下。
Here in this case, we are having 3 parameter's in the Method namely ModelandView.
According to this question, the first parameter is easily understood. It represents the View which will be displayed to the client.
The other two parameters are just like The Pointer and The Holder
Hence you can sum it up like this
ModelAndView(View, Pointer, Holder);
The Pointer just points the information in the The Holder
When the Controller binds the View with this information, then in the said process, you can use The Pointer in the JSP page to access the information stored in The Holder to display that respected information to the client.
Here is the visual depiction of the respected process.
View
View的解释比较简单,它包含了一个路径。比如View的值是Welcome
,就意味着urlPatterns
是Welcome
的文件要被访问了。这个地方可以是servlet,也可以是JSP文件。
Model
Model的理解是我要记录这篇博客的关键。Model的参数分为Pointer
和Holder
,当ViewEngine
被调用的时候,你可以拿着Pointer
去JSP文件中寻找Holder
所存储的信息,然后再把这个信息交给ViewEngine
去呈现在页面上。