<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    推薦淘寶秋冬男裝熱賣網店

    追求無止境

    我的程序人生
    隨筆 - 31, 文章 - 2, 評論 - 20, 引用 - 0
    數據加載中……

    Spring MVC 框架學習筆記之BaseCommandController和AbstractCommandController

     

    Spring的BaseCommandController繼承自AbstractController。在看BaseCommandController之前先看他的繼承類AbstractCommandController是如何實現

    AbstractController的handleInternalRequest方法的:

    protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    Object command = getCommand(request);
    ServletRequestDataBinder binder = bindAndValidate(request, command);
    BindException errors = new BindException(binder.getBindingResult());
    return handle(request, response, command, errors);
    }
    

    getCommand就是BaseCommandController中的方法。

    protected Object getCommand(HttpServletRequest request) throws Exception {
    return createCommand();
    }
    protected final Object createCommand() throws Exception {
    if (this.commandClass == null) {
    throw new IllegalStateException("Cannot create command without commandClass being set - " +
    "either set commandClass or (in a form controller) override formBackingObject");
    }
    if (logger.isDebugEnabled()) {
    logger.debug("Creating new command of class [" + this.commandClass.getName() + "]");
    }
    return BeanUtils.instantiateClass(this.commandClass);
    }
    

    createCommand創建了一個CommandClass的對象。

    然后再看bindAndValidate方法:

    protected final ServletRequestDataBinder bindAndValidate(HttpServletRequest request, Object command)
    throws Exception {
    ServletRequestDataBinder binder = createBinder(request, command);
    BindException errors = new BindException(binder.getBindingResult());
    if (!suppressBinding(request)) {
    binder.bind(request);
    onBind(request, command, errors);
    if (this.validators != null && isValidateOnBinding() && !suppressValidation(request, command, errors)) {
    for (int i = 0; i < this.validators.length; i++) {
    ValidationUtils.invokeValidator(this.validators[i], command, errors);
    }
    }
    onBindAndValidate(request, command, errors);
    }
    return binder;
    }
    

    這個方法首先創建了 DataBinder對象,然后,獲取創建綁定對象時發生的錯誤。報錯在errors。接下來綁定對象,調用onBind處理綁定事件;接下來應用Validator。然后調用onBindAndValidate來處理綁定和驗證事件。最后返回binder。

    處理完之后調用handle方法進行處理。

    綜上所述,AbstractCommandController具有兩個功能:

    1、將請求參數轉換為Command對象。在該Controller中,我們設置一個object對象。然后BaseCommandController將請求的參數進行轉換。如果請求參數有value值,就會調用object的的setValue對象來設置對象里的值。如果請求參數中有address.city.就會調用object中getAddress().setCity()方法來賦值。這個object可以是任意的object,唯一的要求就是這個object類沒有參數。

    2、對數據進行驗證。在轉換和驗證時發生錯誤時,需要在handle(request, response, command, errors)中進行處理。

    posted on 2009-11-25 16:25 追求無止境 閱讀(5383) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
    博客園   IT新聞   Chat2DB   C++博客   博問  
     
    主站蜘蛛池模板: 美女裸身网站免费看免费网站| 婷婷国产偷v国产偷v亚洲| a级毛片免费高清毛片视频| 亚洲国产成人乱码精品女人久久久不卡 | 免费黄网站在线看| 区三区激情福利综合中文字幕在线一区亚洲视频1 | 无码乱肉视频免费大全合集 | 无码不卡亚洲成?人片| 理论亚洲区美一区二区三区| 国产无遮挡吃胸膜奶免费看| 美女无遮挡免费视频网站| 亚洲国产一区视频| 亚洲国产免费综合| 亚洲av永久无码精品表情包| 99久热只有精品视频免费看 | 亚洲另类无码专区首页| 四虎影视永久免费观看网址| 一级毛片在线播放免费| 久久亚洲综合色一区二区三区| 一区二区三区福利视频免费观看| 亚洲精品日韩中文字幕久久久| 青春禁区视频在线观看直播免费| 亚洲国产成人久久综合| 亚洲综合色成在线播放| 久久国产乱子伦精品免费强| 亚洲一区免费在线观看| 免费人成视频在线观看不卡| 中文字幕在线免费视频| 亚洲狠狠狠一区二区三区| 在线观看人成视频免费| 国产精品黄页免费高清在线观看| 久久久无码精品亚洲日韩蜜臀浪潮| 又粗又大又黑又长的免费视频| 亚洲高清毛片一区二区| 亚洲欧洲成人精品香蕉网| 91久久精品国产免费直播| 亚洲AV日韩综合一区| 国产AV无码专区亚洲AV毛网站| 国国内清清草原免费视频99| 人妻无码中文字幕免费视频蜜桃| 亚洲AV成人一区二区三区AV|