Spring MVC中的Controller和Handler之间有什么区别?

编程入门 行业动态 更新时间:2024-10-09 21:23:27
本文介绍了Spring MVC中的Controller和Handler之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Spring MVC的文档有时会提到处理程序"或请求处理程序".例如, docs.spring.io/autorepo/docs/spring/4.0.4.RELEASE/javadoc-api/org/springframework/web/servlet/handler/SimpleUrlHandlerMapping.html 说:

The documentation of Spring MVC sometimes says about "handlers" or "request handlers". For instance, 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的接口( docs.spring.io/spring-framework/docs/2.5.x/api/org/springframework/web/servlet/mvc/Controller .html ).

And sometimes it says about controllers. For instance, there is an interface called org.springframework.web.servlet.mvc.Controller ( 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.

例如,HttpRequestHandler,WebRequestHandler,MessageHandler都是可以与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之间有什么区别?

本文发布于:2023-11-27 09:48:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637573.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么区别   MVC   Spring   Handler   Controller

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!