【问题标题】:ModelAndView in Spring MVCSpring MVC 中的 ModelAndView
【发布时间】:2013-03-18 14:21:33
【问题描述】:

我正在使用 Spring API。我经历了 ModelAndView 类。我在类中有两个返回 Map 的方法。一个是getModel(),另一个是getModelInternal()。他们都返回地图。这些方法有什么区别。 谢谢。

【问题讨论】:

    标签: spring spring-mvc


    【解决方案1】:

    检查 javadoc 的方法:

    /**
     * Return the model map. May return {@code null}.
     * Called by DispatcherServlet for evaluation of the model.
     */
    protected Map<String, Object> getModelInternal() {
        return this.model;
    }
    
    /**
     * Return the model map. Never returns {@code null}.
     * To be called by application code for modifying the model.
     */
    public Map<String, Object> getModel() {
        return getModelMap();
    }
    

    因此,一个由客户端调用 - 另一个由框架调用,一个可为空 - 另一个非空。

    【讨论】:

    • 您能否详细说明一下,应用程序调用是什么意思。例如,如果我们在 Mode 中添加一个对象说 Employee ,这两种方法都会返回什么值。
    • getModel 将由您的代码使用(并且它不为空),getModelInternal 它由 Spring DispatcherServlet(Spring 的一部分)使用,并且可以为空。所以,只需使用 getModel()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-16
    • 1970-01-01
    • 2011-05-24
    • 2019-02-01
    • 2011-06-30
    相关资源
    最近更新 更多