2013-03-18 75 views
0

我正在瀏覽Spring API。我經歷了ModelAndView類。我在課堂上發現了兩個返回Map的mehods。一個是getModel(),另一個是getModelInternal()。他們都返回地圖。這些方法有什麼區別。 謝謝。ModelAndView Spring MVC

回答

2

的方法檢查的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(); 
} 

所以,一個客戶端調用 - 另一個由框架,一個可爲空 - 另一種不能爲空。

+0

您能否就此進行闡述,我們的意思是由應用程序調用。意思是,例如,如果我們在模式中添加一個Object說Employee,那麼這兩個方法都會返回什麼值。 – Kumar 2013-03-18 17:11:38

+0

getModel將被您的代碼使用(並且它不是null),getModelInternal它將被Spring DispatcherServlet(Spring的一部分)使用並且可以爲空。所以,只需使用getModel() – 2013-03-18 20:24:43

相關問題