亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 網站 > 幫助中心 > 正文

SpringMVC ModelAndView的用法使用詳解

2024-07-09 22:42:18
字體:
來源:轉載
供稿:網友

(一)使用ModelAndView類用來存儲處理完后的結果數據,以及顯示該數據的視圖。從名字上看ModelAndView中的Model代表模型,View代表視圖,這個名字就很好地解釋了該類的作用。業務處理器調用模型層處理完用戶請求后,把結果數據存儲在該類的model屬性中,把要返回的視圖信息存儲在該類的view屬性中,然后讓該ModelAndView返回該Spring MVC框架??蚣芡ㄟ^調用配置文件中定義的視圖解析器,對該對象進行解析,最后把結果數據顯示在指定的頁面上。

具體作用:

1、返回指定頁面

ModelAndView構造方法可以指定返回的頁面名稱,

也可以通過setViewName()方法跳轉到指定的頁面 ,

2、返回所需數值

使用addObject()設置需要返回的值,addObject()有幾個不同參數的方法,可以默認和指定返回對象的名字。

1、【其源碼】:熟悉一個類的用法,最好從其源碼入手。

public class ModelAndView {    /** View instance or view name String */   private Object view //該屬性用來存儲返回的視圖信息/** Model Map */ private ModelMap model;//<span >該屬性用來存儲處理后的結果數據</span>  /**  * Indicates whether or not this instance has been cleared with a call to {@link #clear()}.  */ private boolean cleared = false;   /**  * Default constructor for bean-style usage: populating bean  * properties instead of passing in constructor arguments.  * @see #setView(View)  * @see #setViewName(String)  */ public ModelAndView() { }  /**  * Convenient constructor when there is no model data to expose.  * Can also be used in conjunction with <code>addObject</code>.  * @param viewName name of the View to render, to be resolved  * by the DispatcherServlet's ViewResolver  * @see #addObject  */ public ModelAndView(String viewName) {   this.view = viewName; }  /**  * Convenient constructor when there is no model data to expose.  * Can also be used in conjunction with <code>addObject</code>.  * @param view View object to render  * @see #addObject  */ public ModelAndView(View view) {   this.view = view; }  /**  * Creates new ModelAndView given a view name and a model.  * @param viewName name of the View to render, to be resolved  * by the DispatcherServlet's ViewResolver  * @param model Map of model names (Strings) to model objects  * (Objects). Model entries may not be <code>null</code>, but the  * model Map may be <code>null</code> if there is no model data.  */ public ModelAndView(String viewName, Map<String, ?> model) {   this.view = viewName;   if (model != null) {     getModelMap().addAllAttributes(model);   } }  /**  * Creates new ModelAndView given a View object and a model.  * <emphasis>Note: the supplied model data is copied into the internal  * storage of this class. You should not consider to modify the supplied  * Map after supplying it to this class</emphasis>  * @param view View object to render  * @param model Map of model names (Strings) to model objects  * (Objects). Model entries may not be <code>null</code>, but the  * model Map may be <code>null</code> if there is no model data.  */ public ModelAndView(View view, Map<String, ?> model) {   this.view = view;   if (model != null) {     getModelMap().addAllAttributes(model);   } }  /**  * Convenient constructor to take a single model object.  * @param viewName name of the View to render, to be resolved  * by the DispatcherServlet's ViewResolver  * @param modelName name of the single entry in the model  * @param modelObject the single model object  */ public ModelAndView(String viewName, String modelName, Object modelObject) {   this.view = viewName;   addObject(modelName, modelObject); }  /**  * Convenient constructor to take a single model object.  * @param view View object to render  * @param modelName name of the single entry in the model  * @param modelObject the single model object  */ public ModelAndView(View view, String modelName, Object modelObject) {   this.view = view;   addObject(modelName, modelObject); }   /**  * Set a view name for this ModelAndView, to be resolved by the  * DispatcherServlet via a ViewResolver. Will override any  * pre-existing view name or View.  */ public void setViewName(String viewName) {   this.view = viewName; }  /**  * Return the view name to be resolved by the DispatcherServlet  * via a ViewResolver, or <code>null</code> if we are using a View object.  */ public String getViewName() {   return (this.view instanceof String ? (String) this.view : null); }  /**  * Set a View object for this ModelAndView. Will override any  * pre-existing view name or View.  */ public void setView(View view) {   this.view = view; }  /**  * Return the View object, or <code>null</code> if we are using a view name  * to be resolved by the DispatcherServlet via a ViewResolver.  */ public View getView() {   return (this.view instanceof View ? (View) this.view : null); }  /**  * Indicate whether or not this <code>ModelAndView</code> has a view, either  * as a view name or as a direct {@link View} instance.  */ public boolean hasView() {   return (this.view != null); }  /**  * Return whether we use a view reference, i.e. <code>true</code>  * if the view has been specified via a name to be resolved by the  * DispatcherServlet via a ViewResolver.  */ public boolean isReference() {   return (this.view instanceof String); }  /**  * Return the model map. May return <code>null</code>.  * Called by DispatcherServlet for evaluation of the model.  */ protected Map<String, Object> getModelInternal() {   return this.model; }  /**  * Return the underlying <code>ModelMap</code> instance (never <code>null</code>).  */ public ModelMap getModelMap() {   if (this.model == null) {     this.model = new ModelMap();   }   return this.model; }  /**  * Return the model map. Never returns <code>null</code>.  * To be called by application code for modifying the model.  */ public Map<String, Object> getModel() {   return getModelMap(); }   /**  * Add an attribute to the model.  * @param attributeName name of the object to add to the model  * @param attributeValue object to add to the model (never <code>null</code>)  * @see ModelMap#addAttribute(String, Object)  * @see #getModelMap()  */ public ModelAndView addObject(String attributeName, Object attributeValue) {   getModelMap().addAttribute(attributeName, attributeValue);   return this; }  /**  * Add an attribute to the model using parameter name generation.  * @param attributeValue the object to add to the model (never <code>null</code>)  * @see ModelMap#addAttribute(Object)  * @see #getModelMap()  */ public ModelAndView addObject(Object attributeValue) {   getModelMap().addAttribute(attributeValue);   return this; }  /**  * Add all attributes contained in the provided Map to the model.  * @param modelMap a Map of attributeName -> attributeValue pairs  * @see ModelMap#addAllAttributes(Map)  * @see #getModelMap()  */ public ModelAndView addAllObjects(Map<String, ?> modelMap) {   getModelMap().addAllAttributes(modelMap);   return this; }   /**  * Clear the state of this ModelAndView object.  * The object will be empty afterwards.  * <p>Can be used to suppress rendering of a given ModelAndView object  * in the <code>postHandle</code> method of a HandlerInterceptor.  * @see #isEmpty()  * @see HandlerInterceptor#postHandle  */ public void clear() {   this.view = null;   this.model = null;   this.cleared = true; }  /**  * Return whether this ModelAndView object is empty,  * i.e. whether it does not hold any view and does not contain a model.  */ public boolean isEmpty() {   return (this.view == null && CollectionUtils.isEmpty(this.model)); }  /**  * Return whether this ModelAndView object is empty as a result of a call to {@link #clear}  * i.e. whether it does not hold any view and does not contain a model.  * <p>Returns <code>false</code> if any additional state was added to the instance  * <strong>after</strong> the call to {@link #clear}.  * @see #clear()  */ public boolean wasCleared() {   return (this.cleared && isEmpty()); }   /**  * Return diagnostic information about this model and view.  */ @Override public String toString() {   StringBuilder sb = new StringBuilder("ModelAndView: ");   if (isReference()) {     sb.append("reference to view with name '").append(this.view).append("'");   }   else {     sb.append("materialized View is [").append(this.view).append(']');   }   sb.append("; model is ").append(this.model);   return sb.toString(); } 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
久久人91精品久久久久久不卡| 最新日韩中文字幕| 伊人久久精品视频| 欧美成人免费一级人片100| 亚洲国产高清高潮精品美女| 亚洲国产日韩欧美在线图片| 一区二区三区视频免费在线观看| 日韩在线视频播放| 亚洲成人激情视频| 久久久久久久久久婷婷| 亚洲xxxxx| 久久av资源网站| 欧美激情图片区| 精品久久久国产精品999| 亚洲天堂成人在线视频| 欧美日韩成人在线视频| 欧美亚洲视频在线看网址| 亚洲欧美一区二区三区在线| 中文日韩在线观看| 亚洲精品视频在线观看视频| 中文日韩电影网站| 欧美一级成年大片在线观看| 亚洲香蕉伊综合在人在线视看| 亚洲国产日韩一区| 亚洲成人激情视频| 亚洲free嫩bbb| 欧美日韩一二三四五区| 性色av一区二区三区红粉影视| 亚洲一品av免费观看| 国产日本欧美在线观看| 欧美日韩国产二区| 亚洲一区二区三区成人在线视频精品| 高清欧美一区二区三区| 欧美片一区二区三区| 日韩av免费在线| 亚洲天堂开心观看| 亚洲欧洲第一视频| 亚洲理论电影网| 欧美亚洲激情在线| 欧美激情精品久久久久| 欧美成人免费大片| 日韩欧美黄色动漫| 精品国产一区二区三区久久狼5月| 国产精品av网站| 国产精品羞羞答答| 精品国模在线视频| 最新69国产成人精品视频免费| 国产精品看片资源| 国产97在线|日韩| 亚洲成人精品av| 亚洲成人精品视频在线观看| 91精品国产91久久久久久不卡| 91免费视频网站| 欧美在线观看网站| 久久久99免费视频| 亚洲人成电影网站色xx| 国产激情综合五月久久| 成人精品久久一区二区三区| 亚洲一区二区三| 一本色道久久综合狠狠躁篇怎么玩| 国产精品久久久久7777婷婷| 96国产粉嫩美女| 69av在线播放| 国产色综合天天综合网| 亚洲欧美www| 国产一区二区三区视频在线观看| 欧美色另类天堂2015| 久久久久九九九九| 亚洲剧情一区二区| 国产69精品久久久久99| 欧美理论片在线观看| 日韩欧美一区二区三区| 国产日韩欧美日韩| 中文字幕亚洲在线| www.日韩不卡电影av| 欧美专区第一页| 欧美精品久久久久a| 久久精品一本久久99精品| 在线免费看av不卡| 欧美性视频网站| 欧美综合在线观看| 国产精品久久久久久久久久久久| 亚洲一区二区中文| 国产一区二区三区在线免费观看| 91国产一区在线| 在线电影av不卡网址| 色偷偷偷综合中文字幕;dd| 91精品国产综合久久香蕉最新版| 91久久久在线| 国产精品美女在线观看| 久久久噜噜噜久久久| 日韩极品精品视频免费观看| 91香蕉嫩草神马影院在线观看| 日韩精品视频在线免费观看| 亚洲国产又黄又爽女人高潮的| 欧美精品电影免费在线观看| 少妇高潮 亚洲精品| 成人欧美一区二区三区在线| 永久免费看mv网站入口亚洲| 国产精品久久久久免费a∨| 亚洲电影免费观看高清完整版在线观看| 91久久精品久久国产性色也91| 日韩欧美一区二区三区久久| 伊人成人开心激情综合网| 日韩美女在线观看一区| 亚洲成人精品视频在线观看| 欧美一级片久久久久久久| 亚洲国产精品女人久久久| 国产美女被下药99| 国产情人节一区| 在线成人中文字幕| 伊是香蕉大人久久| 日韩美女视频免费在线观看| 欧美大片第1页| 国产精品电影一区| 中文字幕欧美日韩va免费视频| 亚洲а∨天堂久久精品9966| 欧美性xxxx极品hd欧美风情| 国内外成人免费激情在线视频| 国产精品自产拍高潮在线观看| 亚洲天堂成人在线| 欧美激情精品久久久久久大尺度| 国产成人精品综合久久久| 在线观看国产精品淫| 亚洲精品色婷婷福利天堂| 精品无人国产偷自产在线| 国产精品久久久久99| 亚洲国产精久久久久久| 欧美精品在线极品| 91中文字幕在线| 久久亚洲欧美日韩精品专区| 亚洲精品一区中文字幕乱码| 热久久美女精品天天吊色| 亚洲日韩欧美视频| 色噜噜狠狠色综合网图区| 久久精品国产欧美亚洲人人爽| 最近2019中文字幕在线高清| 影音先锋日韩有码| 在线视频一区二区| 欧美福利小视频| 国产精品久久久久久久久| 亚洲第一区第一页| 国产一级揄自揄精品视频| 播播国产欧美激情| 国产精品久久久久久久app| 色综久久综合桃花网| 亚洲成人精品视频在线观看| 夜夜嗨av色综合久久久综合网| 最新国产精品拍自在线播放| 国产精品久久久av| 亚洲自拍偷拍第一页| 久久久久久久久久婷婷| 亚洲第一综合天堂另类专| 欧美最猛性xxxxx(亚洲精品)| 日韩中文字幕视频在线| 亚洲国产精品成人精品| 久久精品在线播放| 色与欲影视天天看综合网| 国产日韩精品入口| 日韩精品在线观看网站| 亚洲影院污污.| 97久久精品国产| 日韩免费在线免费观看| 国产视频精品一区二区三区|