Spring框架使用了哪些设计模式?
使用了大量不同的设计模式,但有一些明显的:
代理 - 大量使用AOP http://static.springframework.org/spring/docs/2.5.x/reference/aop.html#aop-understanding-aop-proxies, and remoting http://static.springframework.org/spring/docs/2.5.x/reference/remoting.html.
Singleton - spring 配置文件中定义的 bean 默认情况下是单例。
模板方法 - 广泛用于处理样板重复代码(例如干净地关闭连接等)。例如Jdbc模板 http://static.springframework.org/spring/docs/2.5.x/reference/jdbc.html#jdbc-JdbcTemplate, Jms模板 http://static.springframework.org/spring/docs/2.5.x/reference/jms.html#jms-jmstemplate, Jpa模板 http://static.springframework.org/spring/docs/2.5.x/reference/orm.html#orm-jpa-template.
更新以下评论:对于 MVC,您可能需要阅读MVC 参考 http://static.springframework.org/spring/docs/2.5.x/reference/mvc.html
MVC 中使用的一些明显模式:
模型视图控制器 https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller:-) 。 Spring MVC 的优点是您的控制器是 POJO,而不是 servlet。这使得控制器的测试变得更加容易。需要注意的一点是,控制器只需要返回一个逻辑视图名称,而视图选择则留给单独的视图解析器 http://static.springframework.org/spring/docs/2.5.x/reference/mvc.html#mvc-viewresolver。这使得为不同的视图技术重用控制器变得更加容易。
前置控制器 https://www.oracle.com/technetwork/java/frontcontroller-135648.html。 Spring提供调度程序Servlet http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/web/servlet/DispatcherServlet.html以确保传入请求被分派到您的控制器。
查看助手 https://www.oracle.com/technetwork/java/viewhelper-139885.html- Spring 有许多自定义 JSP 标记和速度宏,以帮助将代码与视图中的表示分离。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)