在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去呈现在页面上。
本文解析了ModelAndView在Web开发中的角色,如何通过参数View展示客户端内容,以及Pointer和Holder的作用,展示了信息从Model到View的传递过程。
2358

被折叠的 条评论
为什么被折叠?



