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

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

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

    推薦淘寶秋冬男裝熱賣網(wǎng)店

    追求無(wú)止境

    我的程序人生
    隨筆 - 31, 文章 - 2, 評(píng)論 - 20, 引用 - 0
    數(shù)據(jù)加載中……

    Spring MVC 框架學(xué)習(xí)筆記之BaseCommandController和AbstractCommandController

     

    Spring的BaseCommandController繼承自AbstractController。在看BaseCommandController之前先看他的繼承類AbstractCommandController是如何實(shí)現(xiàn)

    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創(chuàng)建了一個(gè)CommandClass的對(duì)象。

    然后再看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;
    }
    

    這個(gè)方法首先創(chuàng)建了 DataBinder對(duì)象,然后,獲取創(chuàng)建綁定對(duì)象時(shí)發(fā)生的錯(cuò)誤。報(bào)錯(cuò)在errors。接下來(lái)綁定對(duì)象,調(diào)用onBind處理綁定事件;接下來(lái)應(yīng)用Validator。然后調(diào)用onBindAndValidate來(lái)處理綁定和驗(yàn)證事件。最后返回binder。

    處理完之后調(diào)用handle方法進(jìn)行處理。

    綜上所述,AbstractCommandController具有兩個(gè)功能:

    1、將請(qǐng)求參數(shù)轉(zhuǎn)換為Command對(duì)象。在該Controller中,我們?cè)O(shè)置一個(gè)object對(duì)象。然后BaseCommandController將請(qǐng)求的參數(shù)進(jìn)行轉(zhuǎn)換。如果請(qǐng)求參數(shù)有value值,就會(huì)調(diào)用object的的setValue對(duì)象來(lái)設(shè)置對(duì)象里的值。如果請(qǐng)求參數(shù)中有address.city.就會(huì)調(diào)用object中g(shù)etAddress().setCity()方法來(lái)賦值。這個(gè)object可以是任意的object,唯一的要求就是這個(gè)object類沒有參數(shù)。

    2、對(duì)數(shù)據(jù)進(jìn)行驗(yàn)證。在轉(zhuǎn)換和驗(yàn)證時(shí)發(fā)生錯(cuò)誤時(shí),需要在handle(request, response, command, errors)中進(jìn)行處理。

    posted on 2009-11-25 16:25 追求無(wú)止境 閱讀(5395) 評(píng)論(0)  編輯  收藏


    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲黄色网站视频| 一二三四免费观看在线电影| 免费国产综合视频在线看| 亚洲人成网站看在线播放| 18以下岁毛片在免费播放| 亚洲色欲或者高潮影院| 免费黄色福利视频| 亚洲伦理一二三四| 免费毛片在线看片免费丝瓜视频| 精品久久久久久久久免费影院| 亚洲爱情岛论坛永久| 日韩免费人妻AV无码专区蜜桃| 久久综合亚洲色一区二区三区| 亚洲一区免费在线观看| 亚洲人成网国产最新在线| 在线观看成人免费| 色多多免费视频观看区一区| 亚洲第一区精品观看| 国产在线观看无码免费视频| 亚洲AV无码成人精品区蜜桃| 4399好看日本在线电影免费| 亚洲av成人片在线观看| 国产自偷亚洲精品页65页| 最好免费观看高清在线| 亚洲成综合人影院在院播放| 波多野结衣久久高清免费 | 亚洲一本综合久久| 99热在线精品免费全部my| 日日摸日日碰夜夜爽亚洲| 亚洲精品无码鲁网中文电影| **实干一级毛片aa免费| 精品久久久久久亚洲中文字幕 | 亚洲伊人久久大香线蕉在观| 国产真实伦在线视频免费观看| 精品乱子伦一区二区三区高清免费播放 | jizz18免费视频| 久久丫精品国产亚洲av| 日韩人妻无码免费视频一区二区三区| 男女猛烈无遮掩视频免费软件 | 久久亚洲精品成人777大小说| 免费毛片a在线观看67194|