<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í)之AbstractFormController以及AbstractFormControll

    在看完BaseCommandController和AbstractCommandController之后,我們?cè)倏碆aseCommandController的另一個(gè)實(shí)現(xiàn)AbstractFormController,以及AbstractFormController的具體實(shí)現(xiàn)SimpleFormController。

    先看看AbstractFormController對(duì)handleRequestInternal的實(shí)現(xiàn):

    protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    // Form submission or new form to show?
    if (isFormSubmission(request)) {
    // Fetch form object from HTTP session, bind, validate, process submission.
    try {
    Object command = getCommand(request);
    ServletRequestDataBinder binder = bindAndValidate(request, command);
    BindException errors = new BindException(binder.getBindingResult());
    return processFormSubmission(request, response, command, errors);
    }
    catch (HttpSessionRequiredException ex) {
    // Cannot submit a session form if no form object is in the session.
    if (logger.isDebugEnabled()) {
    logger.debug("Invalid submit detected: " + ex.getMessage());
    }
    return handleInvalidSubmit(request, response);
    }
    }
    else {
    // New form to show: render form view.
    return showNewForm(request, response);
    }
    }
    這個(gè)方法,首先判斷是不是Form提交,判斷方法是:
    protected boolean isFormSubmission(HttpServletRequest request) {
    return "POST".equals(request.getMethod());
    }
    如果是form提交的話,系統(tǒng)首先創(chuàng)建一個(gè)Command,然后對(duì)數(shù)據(jù)進(jìn)行綁定和驗(yàn)證,之后調(diào)用processFormSubmission方法。showNewForm則調(diào)用showForm。
    在AbstractFormController中里面有兩個(gè)抽象方法:

    protected abstract ModelAndView processFormSubmission(
    HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)
    throws Exception;
    protected abstract ModelAndView showForm(
    HttpServletRequest request, HttpServletResponse response, BindException errors)
    throws Exception;



     

     

    好了,看完AbstractFormController之后,再看看SimpleFormController是如何實(shí)現(xiàn):

    protected ModelAndView processFormSubmission(
    HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)
    throws Exception {

    if (errors.hasErrors()) {
    if (logger.isDebugEnabled()) {
    logger.debug("Data binding errors: " + errors.getErrorCount());
    }
    return showForm(request, response, errors);
    }
    else if (isFormChangeRequest(request, command)) {
    logger.debug("Detected form change request -> routing request to onFormChange");
    onFormChange(request, response, command, errors);
    return showForm(request, response, errors);
    }
    else {
    logger.debug("No errors -> processing submit");
    return onSubmit(request, response, command, errors);
    }
    }
    在上面的方法中,如果有錯(cuò)誤,調(diào)用showForm,來(lái)顯示form。沒(méi)有錯(cuò)誤的話,則調(diào)用onSubmit方法。
    protected final ModelAndView showForm(
    HttpServletRequest request, BindException errors, String viewName, Map controlModel)
    throws Exception {

    // In session form mode, re-expose form object as HTTP session attribute.
    // Re-binding is necessary for proper state handling in a cluster,
    // to notify other nodes of changes in the form object.
    if (isSessionForm()) {
    String formAttrName = getFormSessionAttributeName(request);
    if (logger.isDebugEnabled()) {
    logger.debug("Setting form session attribute [" + formAttrName + "] to: " + errors.getTarget());
    }
    request.getSession().setAttribute(formAttrName, errors.getTarget());
    }

    // Fetch errors model as starting point, containing form object under
    // "commandName", and corresponding Errors instance under internal key.
    Map model = errors.getModel();

    // Merge reference data into model, if any.
    Map referenceData = referenceData(request, errors.getTarget(), errors);
    if (referenceData != null) {
    model.putAll(referenceData);
    }

    // Merge control attributes into model, if any.
    if (controlModel != null) {
    model.putAll(controlModel);
    }

    // Trigger rendering of the specified view, using the final model.
    return new ModelAndView(viewName, model);
    }
    在showForm中,設(shè)置屬性,放在model中,然后在viewName進(jìn)行設(shè)置。
    FormController就是上面的過(guò)程。具體的執(zhí)行過(guò)程和詳細(xì)信息會(huì)在以后的博客中具體介紹。

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


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


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 中文字幕日韩亚洲| 日韩精品成人无码专区免费| 国产午夜无码精品免费看动漫| 久久精品国产影库免费看| 免费人成视频在线观看网站| 999国内精品永久免费观看| 无码中文在线二区免费| 国产麻豆剧传媒精品国产免费| 亚洲精品WWW久久久久久| 亚洲av一综合av一区| 亚洲精品456在线播放| 亚洲欧美aⅴ在线资源| 人妻无码中文字幕免费视频蜜桃| 91精品全国免费观看青青| www视频在线观看免费| 国产大片91精品免费观看男同 | 亚洲精品成人在线| 亚洲AV成人无码久久精品老人 | 黄色片网站在线免费观看| 国产乱子伦精品免费视频| **毛片免费观看久久精品| 日韩免费毛片视频| 久久青青草原亚洲AV无码麻豆| 亚洲人成www在线播放| h视频在线观看免费| 亚洲精品在线免费观看视频 | 亚洲成a人无码av波多野按摩| 亚洲AV无一区二区三区久久| 亚洲无人区码一二三码区别图片 | 人成免费在线视频| 亚洲视频免费播放| 亚洲伊人成无码综合网| 亚洲国产日韩女人aaaaaa毛片在线| 黄页视频在线观看免费| 亚洲日本在线免费观看| 亚洲精品天堂成人片?V在线播放| 亚洲色欲或者高潮影院| 狠狠热精品免费观看| 91免费在线播放| 最新精品亚洲成a人在线观看| 亚洲情A成黄在线观看动漫软件|