`
不吃鱼的猫
  • 浏览: 25283 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

Spring MVC学习笔记二

阅读更多

There are 3 ways for processing mapping from DispatcherServlet to Controller

BeanNameUrlHandlerMapping           map to url based on the name of Controller
SimpleUrlHandlerMapping                  map to url with the collection of properties which configurated in the context configuration files.
CommonsPathMapHandlerMapping   map to url with meta data.

they all implement the HandlerMapping interface.

Utilize multiple mapping processor

xml 代码
  1. < bean   id = "beanNameUrlMapping"   class = "org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" >   
  2.    < property   name = "Order" > < value > 1 </value > </property >   
  3. </bean >   
  4.   
  5. < bean   id = "simpleUrlMapping"   class = "org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" >   
  6.    < property   name = "Order" > < value > 0</ value > </property >   
  7. </bean >   

The smaller the order value is, the higher priority will be get.

 

Spring has a hierarchical controller.
Controller<-AbstractController<-MultiActionController
                                                      <-BaseCommandController<-AbstractFormController<-SimpleFormController
                                                                                                                                                       <-AbstarctWizardFormController
                                                                                                         <-AbstractCommandController

ThrowawayController

BaseCommandController has validator property which can provide the validation functionality.

the Command Object service as VO, which is provide as a property in BaseCommandController.

AbstractWizardFormController is well suited in Corss Page Form situation.
Attention will pay when decide which page should be nevigate. The specified string used(_target1,_finsih,_cancel) come to rescue. P266 Spring in action for details.

There is a little different to process validation in corss page form. 
In this case, there are lots of properties. You should invode validatePage() to validate Command object each time when you jump aross the pages.

  
View Resolver
A View is a bean responsible for reder the result to the user.
How the render happen is depend on your view type.
The ViewResolver is a bridge between logic view name and view bean. 
Spring will consult ViewResolver when decide which view bean should be applied.
There are four types of ViewResolver.
    InternalResourceViewResolver interpret the logic name to a template file(Jsp,Velocity)
    BeanNameViewResolver              to a View bean configurated in the DispatcherServlet context configuration file.
    ResourceBundleViewResolver  to a View Object of a ResourceBundle
    XmlViewResolver                           interpret View Bean from a another xml(not main config files)

Please refer P278 Spring in Action for details.

Mutiple View Resolver can be configurated in the file, the same as the mutiple controller ,the ordr property used for set priortiy to mapping the logic name to view bean . 

Handler Exception

  1. < bean   id = "exceptionResolver"   class = "org.springframeowrok.web.servlet.handler.SimpleMappingExceptionResolver" >   
  2.    < property   name = "exceptionMappings" >   
  3.      < props >   
  4.        < prop   key = "java.lang.Exception" > friendlyError </ prop >   
  5.      </ props >   
  6.    </ property >   
  7. </ bean >   

 

xml 代码
分享到:
评论

相关推荐

    Spring MVC 学习笔记

    以下是对Spring MVC学习笔记的详细解释: 1. **创建项目**: 创建Spring MVC项目通常从构建一个Maven工程开始。在命令行中使用Maven的`archetype:generate`命令创建一个JEE5的Web工程。在提供的例子中,使用了特定...

    Spring MVC学习笔记MD.7z

    这个压缩包“Spring MVC学习笔记MD.7z”包含了作者在学习Spring MVC过程中的笔记、源代码以及相关文档,非常适合初学者或希望深入理解Spring MVC的开发者。 首先,`SpringMVC-Study.7z` 可能是作者整理的Spring MVC...

    spring mvc学习笔记

    ### Spring MVC 学习笔记 #### 一、Spring MVC 核心组件与工作流程 **Spring MVC** 是 **Spring Framework** 的一个重要模块,主要用于构建基于 Web 的应用程序。它提供了简化 Web 开发的一系列功能,包括但不限于...

    Spring MVC 学习笔记 九 json格式的输入和输出

    在这个学习笔记中,我们将深入探讨如何在Spring MVC中处理JSON格式的数据,包括输入和输出。JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,广泛应用于前后端数据传输。 1. **JSON格式简介** ...

    Spring MVC 学习笔记 十二 PDF/Excel格式输出

    本学习笔记主要围绕Spring MVC的使用、配置和核心组件进行深入探讨,旨在帮助开发者更好地理解和掌握这一框架。 在Spring MVC中,Model代表业务逻辑和数据,View负责数据的展示,而Controller处理用户请求,协调...

    Spring MVC 学习笔记 一 创建项目

    **Spring MVC 学习笔记 一 创建项目** 在IT领域,Spring MVC是Java Web开发中的一个强大框架,它简化了构建交互式Web应用程序的过程。本笔记将深入探讨如何创建一个基本的Spring MVC项目,让我们开始吧。 首先,...

    spring MVC学习笔记

    在学习Spring MVC的过程中,我们首先需要了解的是控制器(Controller)的基本概念。控制器是处理用户请求并返回响应给用户的组件。在Spring MVC中,通过@Controller注解标记一个类为控制器。一个控制器类中可以包含...

    Spring MVC 学习笔记(一)

    **Spring MVC 学习笔记(一)** Spring MVC 是 Spring 框架的重要组成部分,它是一个用于构建 Web 应用程序的模型-视图-控制器(MVC)框架。Spring MVC 通过解耦应用程序的不同部分,使开发人员能够更轻松地进行...

    Spring MVC 学习笔记 十一 data binding

    本学习笔记将深入探讨Spring MVC中的数据绑定特性。 1. **数据绑定的基本概念** 数据绑定是Spring MVC中的一种核心功能,它允许我们将HTTP请求参数、JSON或XML数据自动映射到Java对象的属性上。这减少了手动提取...

    Spring MVC 学习笔记 七 controller中其他可用的annotation

    这篇"Spring MVC 学习笔记 七 controller中其他可用的annotation"可能涵盖了除我们常见的`@RequestMapping`之外的其他注解,这些注解使得控制器功能更加丰富和灵活。下面将详细探讨Spring MVC中Controller相关的注解...

    Spring3 MVC 学习笔记 入门

    ### Spring3 MVC 学习笔记入门知识点解析 #### 一、Spring MVC 概念与架构 **Spring MVC** 是 Spring Framework 的一个重要模块,主要用于构建基于 Web 的应用。它实现了 Model-View-Controller(MVC)设计模式,...

    spring_mvc学习笔记

    在Spring MVC的学习过程中,了解和掌握其核心概念与机制至关重要。Spring MVC是Spring框架的一个模块,主要用于构建Web应用程序。在Spring 3.0.x版本中,Spring MVC进行了大量的改进,引入了许多新特性和优化,使其...

    Spring MVC 学习笔记 十四 对locale和theme的支持

    这篇学习笔记将深入探讨这两个概念及其在实际开发中的应用。 1. **Locale(地区设置)支持** - `Locale`是Java中的一个类,用于表示特定的语言和地区。例如,`zh_CN`代表简体中文,`en_US`代表美国英语。 - ...

    Spring框架学习笔记

    这份"Spring框架学习笔记"涵盖了Spring框架的基础知识、核心组件以及高级特性,对于初学者来说是一份宝贵的资料。 一、Spring框架概述 Spring框架是为了解决企业应用开发的复杂性而设计的,它提供了一个全面的基础...

    Spring学习笔记&源码

    本资料“Spring学习笔记&源码”是基于网易云课堂黑马程序员的Spring四天精通课程,旨在帮助学习者深入理解和实践Spring框架。 笔记部分可能会涵盖以下内容: 1. **Spring概述**:介绍Spring框架的历史、特点和主要...

Global site tag (gtag.js) - Google Analytics