首页 > 其他 > 详细

PetClinic 教程

时间:2015-10-20 15:25:12      阅读:384      评论:0      收藏:0      [点我收藏+]

请求控制器

下面的这些Bean类,对于请求控制器来说都是可以访问的,并且,它们在petclinic-servlet.xml这个文件里被定义。

请求控制器使用这些定义把实际的显示和表单处理任务委派给业务控制器类。DispatcherServlet扮演一个请求控制器的角色,通过url映射来转发所有的请求给合适的业务控制器。

业务控制器负责与用户交互,并且把最终的action委派给业务/持久层。


  • 国际化的配置文件

  • 逻辑视图路径与实际视图路径的映射

  • 基于表单的业务控制器和非表单业务控制器



-----

原文如下:

DispatcherServlet

The following beans are accessible to the DispatcherServlet and are defined in the PetClinic petclinic-servlet.xml file. This dispatcher uses these definitions to delegate actual display and form processing tasks to implementations of the Spring org.springframework.web.servlet.mvc.Controller interface. The DispatcherServlet acts as the main application Front Controller and is responsible for dispatching all requests to the appropriate Controller indirectly through a URL mapping handler. These Controllers are responsible for the mechanics of interaction with the user and ultimately delegate action to the Business/Persistence Layers.

  • messageSource is a singleton bean that defines a message source for this ApplicationContext. Messages are loaded from localized "messages_xx" files in the classpath, such as "/WEB-INF/classes/messages.properties" or "/WEB-INF/classes/messages_de.properties".  getMessage() calls to this context will use this source. Child contexts can have their own message sources, which will inherit all messages from this source and are able to define new messages and override ones defined in the primary message source.

  • InternalResourceViewResolver is a singleton bean that defines the view mappings used by the dispatcher. Specifically, logical view names returned by Controllers will be mapped to physical paths using the configured ‘prefix‘ and ‘suffix‘ properties. For example, a logical view name of "vets" will be mapped to "/WEB-INF/jsp/vets.jsp".

  • SimpleMappingExceptionResolver is a singleton bean that defines how exceptions are propagated. Exceptions encountered that are not specified are propagated to the servlet container.

  • <context:component-scan ... /> is used to autodetect the controllers in the org.springframework.samples.petclinic.web package, which are POJOs labeled with the@Controller  annotation.

    • ClinicController is a singleton, annotation-driven MultiActionController that is used by the dispatcher to handle non-form based display tasks. A method is provided to handle each type of request that is supported.

    • In addition, there are 6 singleton, annotation-driven Form controllers, which are used to handle the various Search, Add and Edit form processing tasks for the dispatcher.

  • The form-based controllers within the PetClinic application provide @RequestMapping annotations at the type level for path mapping URLs and @RequestMapping at the method level for request type mappings (e.g., GET and POST). In contrast, ClinicController – which is not form-based – provides @RequestMapping only at the method level for path mapping URLs. DefaultAnnotationHandlerMapping is driven by these annotations and is enabled by default with Java 5+.


PetClinic 教程

原文:http://my.oschina.net/diedai/blog/519354

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!