Spring MVC中的Controller和Handler之间有什么区别? [英] what's difference between Controller and Handler in Spring MVC?

查看:710
本文介绍了Spring MVC中的Controller和Handler之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Spring MVC的文档有时会提到处理程序"或请求处理程序".例如,

The documentation of Spring MVC sometimes says about "handlers" or "request handlers". For instance, http://docs.spring.io/autorepo/docs/spring/4.0.4.RELEASE/javadoc-api/org/springframework/web/servlet/handler/SimpleUrlHandlerMapping.html says:

HandlerMapping接口的实现,以从URL映射到请求处理程序bean

Implementation of the HandlerMapping interface to map from URLs to request handler beans

有时它还涉及到控制器.例如,有一个名为org.springframework.web.servlet.mvc.Controller的接口(

And sometimes it says about controllers. For instance, there is an interface called org.springframework.web.servlet.mvc.Controller ( http://docs.spring.io/spring-framework/docs/2.5.x/api/org/springframework/web/servlet/mvc/Controller.html ).

我的问题是:控制器和处理程序是否相同?

My question is: are Controllers and Handlers the same?

推荐答案

通常来说,控制器是处理程序,但处理程序不必一定是控制器.

Generally speaking, a Controller is Handler, but a Handler doesn't have to be a Controller.

例如,HttpRequestHandlerWebRequestHandlerMessageHandler都是可以与DispatcherServlet一起使用的处理程序. ((@)Controller是用于执行Web请求并返回视图的处理程序.)

For example, HttpRequestHandler, WebRequestHandler, MessageHandler are all handlers which can work with the DispatcherServlet. ( (@)Controller is a handler for executing a web request and returning a view.)

简短地说,Handler只是一个术语,它既不是类也不是接口.并且负责执行映射.

Shortly, Handler is just a term, it is neither a class nor interface. And it is responsible for executing the Mapping.

这篇关于Spring MVC中的Controller和Handler之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆