Spring框架中使用了什么设计模式? [英] What design patterns are used in Spring framework?

查看:469
本文介绍了Spring框架中使用了什么设计模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Spring框架中使用了什么设计模式?

What design patterns are used in Spring framework?

推荐答案

使用了不同的设计模式,但是有很少有明显的例子:

There are loads of different design patterns used, but there are a few obvious ones:

Singleton - 在spring配置文件中定义的bean文件是默认情况下的单例。

Singleton - beans defined in spring config files are singletons by default.

模板方法 - 广泛用于处理样板重复代码(如关闭连接等)。例如, JdbcTemplate JmsTemplate JpaTemplate

Template method - used extensively to deal with boilerplate repeated code (such as closing connections cleanly, etc..). For example JdbcTemplate, JmsTemplate, JpaTemplate.

更新以下注释:对于MVC,您可能需要阅读 MVC参考

Update following comments: For MVC, you might want to read the MVC Reference

在MVC中使用:


  • 模型视图控制器 :-)。 Spring MVC的优点是您的控制器是POJO,而不是servlet。这使得更容易测试控制器。需要注意的一点是控制器只需返回一个逻辑视图名称,视图选择将留给另一个 ViewResolver 。这样可以更轻松地为不同的视图技术重新使用控制器。

  • Model View Controller :-) . The advantage with Spring MVC is that your controllers are POJOs as opposed to being servlets. This makes for easier testing of controllers. One thing to note is that the controller is only required to return a logical view name, and the view selection is left to a separate ViewResolver. This makes it easier to reuse controllers for different view technologies.

前端控制器。 Spring提供了 DispatcherServlet 以确保传入的请求被发送到您的控制器。

Front Controller. Spring provides DispatcherServlet to ensure an incoming request gets dispatched to your controllers.

View Helper - Spring有许多自定义的JSP标签和速度宏,以协助将视图中的代码与演示文稿分开。

View Helper - Spring has a number of custom JSP tags, and velocity macros, to assist in separating code from presentation in views.

这篇关于Spring框架中使用了什么设计模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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