ImageVerifierCode 换一换
格式:DOCX , 页数:19 ,大小:26.46KB ,
资源ID:2780307      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/2780307.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Controller1 详解Spring MVC的控制器Controller.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Controller1 详解Spring MVC的控制器Controller.docx

1、Controller1 详解Spring MVC的控制器ControllerA、Controller接口org.springframework.web.servlet.mvc.Controllerpublic interface Controller控制器是MVC中的C的部分。应用程序的行为可以理解为服务接口,而控制器使用户可以访问所提供的服务。控制器解析用户输入,并将其转换为合理的模型数据,并通过视图(view)展示给用户。Controller是一个接口,它抽象了控制器的概念,这样可以实现不同类型的Controller。如:表单控制器,向导控制器,命令控制器等。Base Controller

2、 interface, representing a component that receives HttpServletRequest and HttpServletResponse instances just like a HttpServlet but is able to participate in an MVC workflow. Controllers are comparable to the notion of a Struts Action.基础Controller接口是一个组件,它接收HttpServletRequest和HttpServletResponse实例,就

3、像一个HttpServlet,但是它可以参与MVC工作流。它相当于Struct中的notion。WorkflowAfter a DispatcherServlet has received a request and has done its work to resolve locales, themes and suchlike, it then tries to resolve a Controller, using a HandlerMapping. When a Controller has been found to handle the request, the handleReq

4、uest method of the located Controller will be invoked; the located Controller is then responsible for handling the actual request and - if applicable - returning an appropriate ModelAndView. So actually, this method is the main entrypoint for the DispatcherServlet which delegates requests to control

5、lers. This method - and also this interface - should preferrably not be implemented by custom controllers directly, since abstract controller also provided by this package already provide a lot of functionality for typical use cases in web applications. A few examples of those controllers: AbstractC

6、ontroller, AbstractCommandController, SimpleFormController.流程在DispatcherServlet接收一个请求,并且完成了locale,theme等的解析工作,之后它将根据HandlerMapping来解析一个Controller。当这个Controller被发现,就使用它来处理这个请求,那么这个Controller的handleRequest方法将被调用。然后这个Controller将负责处理这个实际的请求,若可能的话它将返回一个对应的ModelAndView实例。实际上,这个方法(handleRequest)是Dispatcher

7、Servlet把requets委托到Controller的一个入口。这个方法最好不要由自定义的Controller直接来实现,因为这个包里的抽象controller已经提供许多功能,这些功能满足web应用的常见的用例。例如,AbstractController,AbstractCommandController,,SimpleFormController。So basically any direct implementation of the Controller interface just handles HttpServletRequests and should return a M

8、odelAndView, to be further interpreted by the DispatcherServlet. Any additional functionality such as optional validation, form handling, etc should be obtained through extending one of the abstract controller classes mentioned above. 任何直接实现Controller接口的实例,它只是处理HttpServletRequests并返回一个ModelAndView。任

9、何附加功能,如,可选验证、表单处理等,就需要通过扩展上面提及的抽象类来实现了。抽象方法ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) Process the request and return a ModelAndView object which the DispatcherServlet will render. 处理请求返回ModelAndView对象给DispatcherServlet处理。B、AbstractController抽象类org.springfram

10、ework.web.servlet.mvc.AbstractControllerpublic abstract class AbstractController extends WebContentGenerator implements Controllerjava.lang.Object org.springframework.context.support.ApplicationObjectSupport org.springframework.web.context.support.WebApplicationObjectSupport org.springframework.web.

11、servlet.support.WebContentGenerator org.springframework.web.servlet.mvc.AbstractControllerConvenient superclass for controller implementations, using the Template Method design pattern.Controller接口的抽象基础类,使用Template方法设计模式。Workflow (and that defined by interface):1、handleRequest() will be called by th

12、e DispatcherServlet2、Inspection of supported methods (ServletException if request method is not support)3、If session is required, try to get it (ServletException if not found)4、Set caching headers if needed according to cacheSeconds propery5、Call abstract method handleRequestInternal() (optionally s

13、ynchronizing around the call on the HttpSession), which should be implemented by extending classes to provide actual functionality to return ModelAndView objects.流程1、 DispatcherServlet调用handleRequest()方法。2、 检查支持的方法(若请求方法不支持抛出ServletException)。3、 若需要session,则获取session(若没找到则抛出ServletException)。4、 若需要c

14、acheSeconds属性,则设置缓存头。5、 调用抽象方法handleRequestInternal(可选,在HttpSession上同步调用),这个方法应被它的扩展类实现来提供实际的功能来返回一个ModelAndView的实例。Exposed configuration properties (and those defined by interface):namedefaultdescriptionsupportedMethodsGET,POSTcomma-separated (CSV) list of methods supported by this controller, such

15、 as GET, POST and PUT指定controller支持的方法。requireSessionfalsewhether a session should be required for requests to be able to be handled by this controller. This ensures that derived controller can - without fear of null pointers - call request.getSession() to retrieve a session. If no session can be fo

16、und while processing the request, a ServletException will be thrown指定request是否需要http session。cacheSeconds-1indicates the amount of seconds to include in the cache header for the response following on this request. 0 (zero) will include headers for no caching at all, -1 (the default) will not generateany headersand any positive number will generate headers that state the amount indi

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1