<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)航:
     
    主站蜘蛛池模板: 99精品免费观看| 18以下岁毛片在免费播放| 免费看一级高潮毛片| 国产在线观看xxxx免费| 毛片a级毛片免费观看免下载 | 国产h肉在线视频免费观看| 国产日产成人免费视频在线观看 | 中文字幕a∨在线乱码免费看| 国产一级高清视频免费看| 亚洲综合在线视频| 在线观看亚洲视频| 69xx免费观看视频| 亚洲国产精品成人综合色在线婷婷| 日本永久免费a∨在线视频| www.亚洲精品.com| 一本天堂ⅴ无码亚洲道久久| 一个人免费视频在线观看www| 五月亭亭免费高清在线| 亚洲一区二区三区免费视频 | 亚洲精品高清国产麻豆专区| eeuss草民免费| 大学生一级特黄的免费大片视频| 亚洲男人都懂得羞羞网站| 四虎永久在线精品免费一区二区 | 国产亚洲精品国产福利在线观看| 免费中文字幕一级毛片| 亚洲砖码砖专无区2023| 特级淫片国产免费高清视频| 亚洲毛片无码专区亚洲乱| 免费精品人在线二线三线区别| 麻豆亚洲AV永久无码精品久久| 免费成人福利视频| 精品亚洲成A人在线观看青青| 在线免费一区二区| 一级一级一级毛片免费毛片| 免费一级毛片一级毛片aa| 十八禁在线观看视频播放免费| 久久久久亚洲精品日久生情| 在线看无码的免费网站| 亚洲国产综合自在线另类| 日日操夜夜操免费视频|