毕设 外文文献翻译--Spring的web MVC构架模式
spring mvc框架介绍
spring mvc 框架介绍
Spring MVC 简介
Spring MVC 框架是有一个MVC 框架,通过实现Model-View- Controller 模式来很好地将数据、业务与展现进行分离。
从这样一个角度来
说,Spring MVC 和Struts、Struts2 非常类似。
Spring MVC 的设计是围绕DispatcherServlet 展开的,DispatcherServlet 负责将请求派发到特定的handler。
通过可配置的handler mappings、view resoluTIon、locale 以及theme resoluTIon 来处理请求并且转到对应的视图。
Spring MVC 请求处理的整体流
程如图:
Spring3.x 中定义一个控制器类,必须以@Controller 注解标记。
当控
制器类接收到一个请求时,它会在自己内部寻找一个合适的处理方法来处理
请求。
使用@RequestMapping 注解将方法映射到一些请求上,以便让该方法
处理那些请求。
这种方法就像一般的类中的方法,方法名参数列表和返回值
并不像Struts2 之类的框架有很强的限制。
方法参数列表具体以及返回值具体
都有哪些,这里先不细说。
这篇博客的目的在于简单介绍如何快速上手使用Spring MVC 框架。
MVC框架中英文对照外文翻译文献
MVC框架中英⽂对照外⽂翻译⽂献中英⽂对照外⽂翻译⽂献(⽂档含英⽂原⽂和中⽂翻译)译⽂:Web 2.0下的Spring MVC框架摘要 - 当要建⽴丰富⽤户体验的WEB应⽤时,有⼤量的WED应⽤框架可以使⽤,却很少有该选择哪⼀种的指导。
WEB 2.0应⽤允许个体管理他们⾃⼰的在线⽹页,并能与其他在线⽤户和服务器共享。
这样分享需要访问控制器来实现。
然⽽,现有的访问控制器解决⽅案不是令⼈很满意。
因为在开放且由⽤户主导的WEB环境下,它满⾜不了⽤户的功能需求。
MVC框架是在所有的WEB开发框架中最受欢迎的。
模型-视图-控制器(MVC)是⼀种软件架构,如今被认为是⼀种体系结构在软件⼯程模式中使⽤。
该模式从⽤户界⾯(输⼊和演⽰)分离出了“领域逻辑”(基于⽤户的应⽤逻辑),它允许独⽴地开发,测试和维护每个分离的部分。
模型-视图-控制器(MVC)模型创建的应⽤分离为不同的层次应⽤,同时在每两者之间建⽴松散的耦合。
关键字 - Spring MVC, 结构, XStudio, SOA, 控制器I.绪论如何确切地定义⼀个⽹站为“WEB 2.0”的呢?关于这有着许多不同见解,使它很难精确地下⼀个确切的定论。
但当我们将所有的WEB开发框架过⼀遍之后它就会变得清晰了。
各种基于WEB开发的架构如下:●Ntier架构(Ntier Architecture)在软件⼯程中,多层架构(常被称为n-tier架构)是⼀种表⽰层,应⽤处理层和数据管理层在逻辑上分开处理的客户端-服务器架构。
例如,⼀个应⽤在⽤户与数据库之间使⽤中间件提供数据请求服务就⽤到了多层体系结构。
最为⼴泛应⽤的多层体系结构是三层架构。
N-tier 应⽤架构为开发者提供了⽤来创建了⼀个灵活且可复⽤的模型。
通过打破应⽤层次,开发者只需修改或添加⼀个特定的层,⽽不是要去重写⼀遍整个应⽤。
它需要有⼀个表⽰层,⼀个业务层或者数据访问层和⼀个数据层。
层(layer)和层(tier)之间的概念常常是可以互换的。
SSM英文文献翻译
中南大学CentralSouthUniversity 本科毕业设计英文文献翻译题目学生姓名学号指导教师学院专业班级二○一六年一月八日Spring 的web MVC 构架模式Juergen Hoeller1、介绍:Spring 的应用构架当你第一次看到并接触Spring框架的时候,你一定会在心里想到;“哦哦,不不,这又是另一种Web构架”。
这篇文章将会指出Spring框架不是什么特殊的web框架,而是一个通用的轻量级的应用程序框架,在专用网络支持下的应用程序框架。
并且它会告诉你Spring框架明显区别于其他轻量级application framework,它将专注于web的支持,与struts和webwork有着明显的区别。
在和struts和webwork的对比上之中,Spring框架是一个服务于所有层面上的application framework:提供了bean的配置基础,AOP的支持,JDBC的提取框架,抽象事务支持,等等诸如此类。
它有一个非常显著的特点:在某个层面上如果你不需要Spring的支持,它有一个非常显著的特点:在某个层面上如果你不需要Spring的支持,你就可以不使用Spring框架的class(类),只使用它的某一部分的功能。
从它的设计理念,你可以看到Spring框架帮助你实现了真正的逻辑层和web层的成功分离:例如:一个校验应用将不用依靠controllers,就可以实现。
这样的目标是更好的重用和易测:过分依靠不必要的容器和框架将不能实现这一点。
当然,Spring的自己本身的web支持和通常框架模式的细致完整。
然而,Spring替换struts,webwork或者其他的web方案非常的容易。
这个对于Spring 的web支持或者不同的地方,Spring允许你在web容器里面建立一个中间层,在测试环境或者标准独立的应用里面来设置重用你的商务逻辑。
还有就是在J2EE环境里面,可以让你你的商务逻辑不必依靠容器提供的服务,就比如像JTA,EJB的支持。
Spring相关的外文文献和翻译(毕设论文必备)
附录1 外文原文Introducing the Spring FrameworkThe Spring Framework: a popular open source application framework that addresses many of the issues outlined in this book. This chapter will introduce the basic ideas of Spring and dis-cuss the central “bean factory”lightweight Inversion-of-Control (IoC) container in detail.Spring makes it particularly easy to implement lightweight, yet extensible, J2EE archi-tectures. It provides an out-of-the-box implementation of the fundamental architectural building blocks we recommend. Spring provides a consistent way of structuring your applications, and provides numerous middle tier features that can make J2EE development significantly easier and more flexible than in traditional approaches.The basic motivations for Spring are:To address areas not well served by other frameworks. There are numerous good solutions to specific areas of J2EE infrastructure: web frameworks, persistence solutions, remoting tools, and so on. However, integrating these tools into a comprehensive architecture can involve significant effort, and can become a burden. Spring aims to provide an end-to-end solution, integrating spe-cialized frameworks into a coherent overall infrastructure. Spring also addresses some areas that other frameworks don’t. For example, few frameworks address generic transaction management, data access object implementation, and gluing all those things together into an application, while still allowing for best-of-breed choice in each area. Hence we term Spring an application framework, rather than a web framework, IoC or AOP framework, or even middle tier framework.To allow for easy adoption. A framework should be cleanly layered, allowing the use of indi-vidual features without imposing a whole world view on the application. Many Spring features, such as the JDBC abstraction layer or Hibernate integration, can be used in a library style or as part of the Spring end-to-end solution.To deliver ease of use. As we’ve noted, J2EE out of the box is relatively hard to use to solve many common problems. A good infrastructure framework should make simple tasks simple to achieve, without forcing tradeoffs for future complex requirements (like distributed transactions) on the application developer. It should allow developers to leverage J2EE services such as JTA where appropriate, but to avoid dependence on them in cases when they are unnecessarily complex.To make it easier to apply best practices. Spring aims to reduce the cost of adhering to best practices such as programming to interfaces, rather than classes, almost to zero. However, it leaves the choice of architectural style to the developer.Non-invasiveness. Application objects should have minimal dependence on the framework. If leveraging a specific Spring feature, an object should depend only on that particular feature, whether by implementing a callback interface or using the framework as a class library. IoC and AOP are the key enabling technologies for avoiding framework dependence.Consistent configuration. A good infrastructure framework should keep application configuration flexible and consistent, avoiding the need for custom singletons and factories. A single style should be applicable to all configuration needs, from the middle tier to web controllers.Ease of testing. Testing either whole applications or individual application classes in unit tests should be as easy as possible. Replacing resources or application objects with mock objects should be straightforward.To allow for extensibility. Because Spring is itself based on interfaces, rather than classes, it is easy to extend or customize it. Many Spring components use strategy interfaces, allowing easy customization.A Layered Application FrameworkChapter 6 introduced the Spring Framework as a lightweight container, competing with IoC containers such as PicoContainer. While the Spring lightweight container for JavaBeans is a core concept, this is just the foundation for a solution forall middleware layers.Basic Building Blockspring is a full-featured application framework that can be leveraged at many levels. It consists of multi-ple sub-frameworks that are fairly independent but still integrate closely into a one-stop shop, if desired. The key areas are:Bean factory. The Spring lightweight IoC container, capable of configuring and wiring up Java-Beans and most plain Java objects, removing the need for custom singletons and ad hoc configura-tion. Various out-of-the-box implementations include an XML-based bean factory. The lightweight IoC container and its Dependency Injection capabilities will be the main focus of this chapter.Application context. A Spring application context extends the bean factory concept by adding support for message sources and resource loading, and providing hooks into existing environ-ments. Various out-of-the-box implementations include standalone application contexts and an XML-based web application context.AOP framework. The Spring AOP framework provides AOP support for method interception on any class managed by a Spring lightweight container. It supports easy proxying of beans in a bean factory, seamlessly weaving in interceptors and other advice at runtime. Chapter 8 dis-cusses the Spring AOP framework in detail. The main use of the Spring AOP framework is to provide declarative enterprise services for POJOs.Auto-proxying. Spring provides a higher level of abstraction over the AOP framework and low-level services, which offers similar ease-of-use to .NET within a J2EE context. In particular, the provision of declarative enterprise services can be driven by source-level metadata.Transaction management. Spring provides a generic transaction management infrastructure, with pluggable transaction strategies (such as JTA and JDBC) and various means for demarcat-ing transactions in applications. Chapter 9 discusses its rationale and the power and flexibility that it offers.DAO abstraction. Spring defines a set of generic data access exceptions that canbe used for cre-ating generic DAO interfaces that throw meaningful exceptions independent of the underlying persistence mechanism. Chapter 10 illustrates the Spring support for DAOs in more detail, examining JDBC, JDO, and Hibernate as implementation strategies.JDBC support. Spring offers two levels of JDBC abstraction that significantly ease the effort of writing JDBC-based DAOs: the org.springframework.jdbc.core package (a template/callback approach) and the org.springframework.jdbc.object package (modeling RDBMS operations as reusable objects). Using the Spring JDBC packages can deliver much greater pro-ductivity and eliminate the potential for common errors such as leaked connections, compared with direct use of JDBC. The Spring JDBC abstraction integrates with the transaction and DAO abstractions.Integration with O/R mapping tools. Spring provides support classes for O/R Mapping tools like Hibernate, JDO, and iBATIS Database Layer to simplify resource setup, acquisition, and release, and to integrate with the overall transaction and DAO abstractions. These integration packages allow applications to dispense with custom ThreadLocal sessions and native transac-tion handling, regardless of the underlyingO/R mapping approach they work with.Web MVC framework. Spring provides a clean implementation of web MVC, consistent with the JavaBean configuration approach. The Spring web framework enables web controllers to be configured within an IoC container, eliminating the need to write any custom code to access business layer services. It provides a generic DispatcherServlet and out-of-the-box controller classes for command and form handling. Request-to-controller mapping, view resolution, locale resolution and other important services are all pluggable, making the framework highly extensi-ble. The web framework is designed to work not only with JSP, but with any view technology, such as Velocity—without the need for additional bridges. Chapter 13 discusses web tier design and the Spring web MVC framework in detail.Remoting support. Spring provides a thin abstraction layer for accessing remoteservices without hard-coded lookups, and for exposing Spring-managed application beans as remote services. Out-of-the-box support is included for RMI, Caucho’s Hessian and Burlap web service protocols, and WSDL Web Services via JAX-RPC. Chapter 11 discusses lightweight remoting.While Spring addresses areas as diverse as transaction management and web MVC, it uses a consistent approach everywhere. Once you have learned the basic configuration style, you will be able to apply it in many areas. Resources, middle tier objects, and web components are all set up using the same bean configuration mechanism. You can combine your entire configuration in one single bean definition file or split it by application modules or layers; the choice is up to you as the application developer. There is no need for diverse configuration files in a variety of formats, spread out across the application.Spring on J2EEAlthough many parts of Spring can be used in any kind of Java environment, it is primarily a J2EE application framework. For example, there are convenience classes for linking JNDI resources into a bean factory, such as JDBC DataSources and EJBs, and integration with JTA for distributed transaction management. In most cases, application objects do not need to work with J2EE APIs directly, improving reusability and meaning that there is no need to write verbose, hard-to-test, JNDI lookups.Thus Spring allows application code to seamlessly integrate into a J2EE environment without being unnecessarily tied to it. You can build upon J2EE services where it makes sense for your application, and choose lighter-weight solutions if there are no complex requirements. For example, you need to use JTA as transaction strategy only if you face distributed transaction requirements. For a single database, there are alternative strategies that do not depend on a J2EE container. Switching between those transac-tion strategies is merely a matter of configuration; Spring’s consistent abstraction avoids any need to change application code.Spring offers support for accessing EJBs. This is an important feature (andrelevant even in a book on “J2EE without EJB”) because the use of dynamic proxies as codeless client-side business delegates means that Spring can make using a local stateless session EJB an implementation-level, rather than a fundamen-tal architectural, choice. Thus if you want to use EJB, you can within a consistent architecture; however, you do not need to make EJB the cornerstone of your architecture. This Spring feature can make devel-oping EJB applications significantly faster, because there is no need to write custom code in service loca-tors or business delegates. Testing EJB client code is also much easier, because it only depends on the EJB’s Business Methods interface (which is not EJB-specific), not on JNDI or the EJB API.Spring also provides support for implementing EJBs, in the form of convenience superclasses for EJB implementation classes, which load a Spring lightweight container based on an environment variable specified in the ejb-jar.xml deployment descriptor. This is a powerful and convenient way of imple-menting SLSBs or MDBs that are facades for fine-grained POJOs: a best practice if you do choose to implement an EJB application. Using this Spring feature does not conflict with EJB in any way—it merely simplifies following good practice.Introducing the Spring FrameworkThe main aim of Spring is to make J2EE easier to use and promote good programming practice. It does not reinvent the wheel; thus you’ll find no logging packages in Spring, no connection pools, no distributed transaction coordinator. All these features are provided by other open source projects—such as Jakarta Commons Logging (which Spring uses for all its log output), Jakarta Commons DBCP (which can be used as local DataSource), and ObjectWeb JOTM (which can be used as transaction manager)—or by your J2EE application server. For the same reason, Spring doesn’t provide an O/R mapping layer: There are good solutions for this problem area, such as Hibernate and JDO.Spring does aim to make existing technologies easier to use. For example, although Spring is not in the business of low-level transaction coordination, it does provide an abstraction layer over JTA or any other transaction strategy. Spring is alsopopular as middle tier infrastructure for Hibernate, because it provides solutions to many common issues like SessionFactory setup, ThreadLocal sessions, and exception handling. With the Spring HibernateTemplate class, implementation methods of Hibernate DAOs can be reduced to one-liners while properly participating in transactions.The Spring Framework does not aim to replace J2EE middle tier services as a whole. It is an application framework that makes accessing low-level J2EE container ser-vices easier. Furthermore, it offers lightweight alternatives for certain J2EE services in some scenarios, such as a JDBC-based transaction strategy instead of JTA when just working with a single database. Essentially, Spring enables you to write appli-cations that scale down as well as up.Spring for Web ApplicationsA typical usage of Spring in a J2EE environment is to serve as backbone for the logical middle tier of a J2EE web application. Spring provides a web application context concept, a powerful lightweight IoC container that seamlessly adapts to a web environment: It can be accessed from any kind of web tier, whether Struts, WebWork, Tapestry, JSF, Spring web MVC, or a custom solution.The following code shows a typical example of such a web application context. In a typical Spring web app, an applicationContext.xml file will reside in theWEB-INF directory, containing bean defini-tions according to the “spring-beans”DTD. In such a bean definition XML file, business objects and resources are defined, for example, a “myDataSource”bean, a “myInventoryManager”bean, and a “myProductManager”bean. Spring takes care of their configuration, their wiring up, and their lifecycle.<beans><bean id=”myDataSource”class=”org.springframework.jdbc. datasource.DriverManagerDataSource”><property name=”driverClassName”> <value>com.mysql.jdbc.Driver</value></property> <property name=”url”><value>jdbc:mysql:myds</value></property></bean><bean id=”myInventoryManager”class=”ebusiness.DefaultInventoryManager”> <property name=”dataSource”><ref bean=”myDataSource”/> </property></bean><bean id=”myProductManager”class=”ebusiness.DefaultProductManager”><property name=”inventoryManager”><ref bean=”myInventoryManager”/> </property><property name=”retrieveCurrentStock”> <value>true</value></property></bean></beans>By default, all such beans have “singleton”scope: one instance per context. The “myInventoryManager”bean will automatically be wired up with the defined DataSource, while “myProductManager”will in turn receive a reference to the “myInventoryManager”bean. Those objects (traditionally called “beans”in Spring terminology) need to expose only the corresponding bean properties or constructor arguments (as you’ll see later in this chapter); they do not have to perform any custom lookups.A root web application context will be loaded by a ContextLoaderListener that is defined in web.xml as follows:<web-app><listener> <listener-class>org.springframework.web.context.ContextLoaderListener </listener-class></listener>...</web-app>After initialization of the web app, the root web application context will beavailable as a ServletContext attribute to the whole web application, in the usual manner. It can be retrieved from there easily via fetching the corresponding attribute, or via a convenience method in org.springframework.web.context.support.WebApplicationContextUtils. This means that the application context will be available in any web resource with access to the ServletContext, like a Servlet, Filter, JSP, or Struts Action, as follows:WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(servletContext);The Spring web MVC framework allows web controllers to be defined as JavaBeans in child application contexts, one per dispatcher servlet. Such controllers can express dependencies on beans in the root application context via simple bean references. Therefore, typical Spring web MVC applications never need to perform a manual lookup of an application context or bean factory, or do any other form of lookup.Neither do other client objects that are managed by an application context themselves: They can receive collaborating objects as bean references.The Core Bean FactoryIn the previous section, we have seen a typical usage of the Spring IoC container in a web environment: The provided convenience classes allow for seamless integration without having to worry about low-level container details. Nevertheless, it does help to look at the inner workings to understand how Spring manages the container. Therefore, we will now look at the Spring bean container in more detail, starting at the lowest building block: the bean factory. Later, we’ll continue with resource setup and details on the application context concept.One of the main incentives for a lightweight container is to dispense with the multitude of custom facto-ries and singletons often found in J2EE applications. The Spring bean factory provides one consistent way to set up any number of application objects, whether coarse-grained components or fine-grained busi-ness objects. Applying reflection and Dependency Injection, the bean factory can host components that do not need to be aware of Spring at all. Hence we call Spring a non-invasiveapplication framework.Fundamental InterfacesThe fundamental lightweight container interface isorg.springframework.beans.factory.Bean Factory. This is a simple interface, which is easy to implement directly in the unlikely case that none of the implementations provided with Spring suffices. The BeanFactory interface offers two getBean() methods for looking up bean instances by String name, with the option to check for a required type (and throw an exception if there is a type mismatch).public interface BeanFactory {Object getBean(String name) throws BeansException;Object getBean(String name, Class requiredType) throws BeansException;boolean containsBean(String name);boolean isSingleton(String name) throws NoSuchBeanDefinitionException;String[] getAliases(String name) throws NoSuchBeanDefinitionException;}The isSingleton() method allows calling code to check whether the specified name represents a sin-gleton or prototype bean definition. In the case of a singleton bean, all calls to the getBean() method will return the same object instance. In the case of a prototype bean, each call to getBean() returns an inde-pendent object instance, configured identically.The getAliases() method will return alias names defined for the given bean name, if any. This mecha-nism is used to provide more descriptive alternative names for beans than are permitted in certain bean factory storage representations, such as XML id attributes.The methods in most BeanFactory implementations are aware of a hierarchy that the implementation may be part of. If a bean is not found in the current factory, the parent factory will be asked, up until the root factory. From the point of view of a caller, all factories in such a hierarchy will appear to be merged into one. Bean definitions in ancestor contexts are visible to descendant contexts, but not the reverse.All exceptions thrown by the BeanFactory interface and sub-interfaces extend org.springframework. beans.BeansException, and are unchecked. This reflects the fact that low-level configuration prob-lems are not usually recoverable: Hence, application developers can choose to write code to recover from such failures if they wish to, but should not be forced to write code in the majority of cases where config-uration failure is fatal.Most implementations of the BeanFactory interface do not merely provide a registry of objects by name; they provide rich support for configuring those objects using IoC. For example, they manage dependen-cies between managed objects, as well as simple properties. In the next section, we’ll look at how such configuration can be expressed in a simple and intuitive XML structure.The sub-interface org.springframework.beans.factory.ListableBeanFactory supports listing beans in a factory. It provides methods to retrieve the number of beans defined, the names of all beans, and the names of beans that are instances of a given type:public interface ListableBeanFactory extends BeanFactory {int getBeanDefinitionCount();String[] getBeanDefinitionNames();String[] getBeanDefinitionNames(Class type);boolean containsBeanDefinition(String name);Map getBeansOfType(Class type, boolean includePrototypes,boolean includeFactoryBeans) throws BeansException}The ability to obtain such information about the objects managed by a ListableBeanFactory can be used to implement objects that work with a set of other objects known only at runtime.In contrast to the BeanFactory interface, the methods in ListableBeanFactory apply to the current factory instance and do not take account of a hierarchy that the factory may be part of. The org.spring framework.beans.factory.BeanFactoryUtils class provides analogous methods that traverse an entire factory hierarchy.There are various ways to leverage a Spring bean factory, ranging from simple bean configuration to J2EE resource integration and AOP proxy generation. The bean factory is the central, consistent way of setting up any kind of application objects in Spring, whether DAOs, business objects, or web controllers. Note that application objects seldom need to work with the BeanFactory interface directly, but are usu-ally configured and wired by a factory without the need for any Spring-specific code.For standalone usage, the Spring distribution provides a tiny spring-core.jar file that can be embed-ded in any kind of application. Its only third-party dependency beyond J2SE 1.3 (plus JAXP for XML parsing) is the Jakarta Commons Logging API.The bean factory is the core of Spring and the foundation for many other services that the framework offers. Nevertheless, the bean factory can easily be usedstan-dalone if no other Spring services are required.附录2 中文译文Spring框架介绍Spring框架:这是一个流行的开源应用框架,它可以解决很多问题。
MVC设计模式THE-MVC-WEB-DESIGN-PATTERN大学毕业论文外文文献翻译及原文
毕业设计(论文)外文文献翻译文献、资料中文题目:MVC设计模式文献、资料英文题目:THE MVC-WEB DESIGN PATTERN文献、资料来源:文献、资料发表(出版)日期:院(部):专业:班级:姓名:学号:指导教师:翻译日期: 2017.02.14MVC设计模式Ralph F. Grove计算机科学,詹姆斯麦迪逊大学,哈里森堡,美国弗吉尼亚州***************Eray Ozkan计算机科学,詹姆斯麦迪逊大学,哈里森堡,美国弗吉尼亚州*****************关键字:web,web框架,设计模式,模型-视图-控制器模式摘要:模型-视图-控制器模式被引用为许多web开发框架的基础架构。
然而,用于web开发的MVC 版本随着原来的Smalltalk的MVC的演变而发生了一些改变。
本文介绍了对这些变化的分析,并提出了一种独立的Web-MVC模式,用于更准确的描述MVC是如何在web框架中实现的。
1.介绍模型-视图-控制器(Modle-View-Controller,MVC)设计模式被一些web应用框架作为基础架构,例如,Rails,以及Struts。
MVC最初是在施乐帕克研究中心(Goldberg和Robson,1985)开发的Smalltalk编程环境中实现的。
为了适应web框架,MVC已经演变成了另一种方式,最终成为一种不同于其他任何设计模式,也与原始的Smaltalk完全不同的模式的实现。
本文的第一个目标是介绍MVC设计模式,其中包括它的原始形态(第2节)以及现代众所周知的用于web应用框架的变更后的形态(第3节)。
第二个目标是对这个模式演变后发生的变化进行评估,同时呈现演变后版本的有效性(第3节)。
最后,我们提出了一个标准的MVC-Web设计模式的描述,用于反映目前在web框架中模式的使用,同时又能保持原始的MVC中令人满意的特性。
基于MVC的web应用框架的修订版本已经被提出了(Chun, Yanhua, 和Hanhong, 2003) (Barrett和Delaney, 2004)。
SpringMVC框架详解
SpringMVC框架详解随着Web应用程序变得越来越复杂,使用适当的框架变得越来越重要。
SpringMVC是一个流行的Java Web框架,它提供了许多功能,使开发Web应用程序更容易和更快速。
本文将对SpringMVC框架进行详细介绍,包括其架构、工作流程、控制器、视图和模型等方面的内容。
1. SpringMVC架构SpringMVC框架基于Model-View-Controller(MVC)架构。
在这种架构中,应用程序被分为三个组件,分别是:1. Model:负责管理数据的处理和存储。
2. View:负责呈现数据给用户的界面。
3. Controller:负责接收用户的请求和处理数据,控制应用程序的行为。
SpringMVC通过DispatcherServlet实现了这种MVC架构。
DispatcherServlet是一个前端控制器(Front Controller),它接收所有的客户端请求并将其分配给相应的处理程序。
2. SpringMVC的工作流程SpringMVC框架具有以下的工作流程:1. 用户发送请求到DispatcherServlet。
2. DispatcherServlet收到请求后,根据配置文件中的URL映射找到相应的Controller。
3. Controller接收请求,并将数据传递给Service层。
4. Service层对数据进行处理,并将处理结果返回给Controller。
5. Controller根据视图解析器的配置选择相应的视图,将处理结果传递给视图并渲染。
6. 视图呈现处理结果,并将其返回给客户端。
3. SpringMVC的控制器控制器是SpringMVC架构中最重要的组件之一。
它负责接收客户端请求,并根据请求的类型执行相应的逻辑。
SpringMVC提供了以下几种类型的控制器:1. @Controller:该注解标注的类被SpringMVC视为控制器。
2. @RestController:可以理解为@Controller和@ResponseBody的组合注解。
外文翻译---J2EE WEB应用架构分析
附录附录一:文献资料原文J2EE WEB应用架构分析1、架构概述J2EE体系包括java server pages(JSP) ,java SERVLET, enterprise bean,WEB service等技术。
这些技术的出现给电子商务时代的WEB应用程序的开发提供了一个非常有竞争力的选择。
怎样把这些技术组合起来形成一个适应项目需要的稳定架构是项目开发过程中一个非常重要的步骤。
完成这个步骤可以形成一个主要里程碑基线。
形成这个基线有很多好处:各种因数初步确定:为了形成架构基线,架构设计师要对平台(体系)中的技术进行筛选,各种利弊的权衡。
往往架构设计师在这个过程中要阅读大量的技术资料,听取项目组成员的建议,考虑领域专家的需求,考虑赞助商成本(包括开发成本和运行维护成本)限额。
一旦架构设计经过评审,这些因数初步地就有了在整个项目过程中的对项目起多大作用的定位。
定向技术培训:一旦架构师设计的架构得到了批准形成了基线,项目开发和运行所采用的技术基本确定下来了。
众多的项目经理都会对预备项目组成员的技术功底感到担心;他们需要培训部门提供培训,但就架构师面对的技术海洋,项目经理根本就提不出明确的技术培训需求。
怎不能够对体系中所有技术都进行培训吧!有了架构里程碑基线,项目经理能确定这个项目开发会采用什么技术,这是提出培训需求应该是最精确的。
不过在实际项目开发中,技术培训可以在基线确定之前与架构设计并发进行。
角色分工:有了一个好的架构蓝图,我们就能准确划分工作。
如网页设计,JSP 标签处理类设计,SERVLET 设计,session bean设计,还有各种实现。
这些任务在架构蓝图上都可以清晰地标出位置,使得项目组成员能很好地定位自己的任务。
一个好的架构蓝图同时也能规范化任务,能很好地把任务划分为几类,在同一类中的任务的工作量和性质相同或相似。
这样工作量估计起来有一个非常好的基础。
运行维护:前面说过各个任务在架构图上都有比较好的定位。
Spring的web-MVC构架模式大学毕业论文外文文献翻译及原文
毕业设计(论文)外文文献翻译文献、资料中文题目:Spring的web MVC 构架模式文献、资料英文题目:Web MVC with the Spring Framework 文献、资料来源:文献、资料发表(出版)日期:院(部):专业:班级:姓名:学号:指导教师:翻译日期: 2017.02.14翻译文稿1、Spring的web MVC 构架模式Juergen Hoeller1.介绍:Spring 应用构架当你第一次看到Spring的时候,你一定会说:"哦不,又一种web 构架".这篇文章将告诉你Spring明显区别于其他轻量级application framework, 它将专注于web的支持,与struts 和 webwork有着明显的区别。
在和struts 和 webwork的对比上,Spring是一个服务于所有层面的application framework:提供了bean的配置基础,AOP的支持,JDBC的提取框架,抽象事务支持,等等。
它有一个非常显著的特点:在某个层面上如果你不需要Spring的支持,你就可以不使用String的class,只使用它的某一部分的功能。
从它的设计理念,你可以看到String 帮助你实现了真正的逻辑层和web层的分离:例如。
一个校验应用将不用依靠controllers,就可以实现。
这样的目标是更好的重用和易测:过分依靠不必要的容器和框架将不能实现这一点。
当然,Spring 的自己的web支持和通常框架模式的细致完整.然而,Spring 替换struts,webwork或者其他的web方案非常的容易.对于Spring的web支持或者不同的地方,Spring 允许你在web容器里面建立一个中间层,在测试环境或者标准独立的应用里面来设置重用你的商务逻辑.还有在J2EE环境里面,你的商务逻辑不必依靠容器提供的服务,像JTA ,EJB的支持.良好的构架的web应用可以运行在任何容器上,如,Tomcat 或者 Resin. 值得注意的是,Spring 不是和已经存在的解决方案进行竞争. 我们鼓励结合标准的技术,如, Servlet, JSP, JTA, JNDI, JDBC, and JDO, 和非常匹配的工具,如,Hibernate, Velocity, Log4J, and Caucho's Hessian/Burlap.这个框架的的设计思想是在你的应用需要改良的时候,你将会做一些技术的选择:例如,如果你需要分布式事务处理,你可能需要用Spring的Jta TransactionManager 来实现JTA服务.或者,用DataSourceTransactionManager or HibernateTransactionManager 来实现美妙完美的单个数据库交换。
毕业论文外文翻译-Spring的web MVC 构架模式
Web MVC with the Spring FrameworkJuergen Hoeller1. Introduction: Spring the Application FrameworkWhen first confronted with the Spring Framework, one might be tempted to think: "Oh no, not yet another web framework". This article will outline why Spring isn't particularly a web framework but a generic lightweight application framework with dedicated web support, and show the architectural differences to Struts and WebWork In contrast to Struts or WebWork, Spring is an application framework for all layers: It offers a bean configuration foundation, AOP support, a JDBC abstraction framework, abstract transaction support, etc. It is a very non-intrusive effort: Your application classes do not need to depend on any Spring classes if not necessary, and you can reuse every part on its own if you like to. From its very design, the framework encourages clean separation of tiers, most importantly web tier and business logic: e.g. the validation framework does not depend on web controllers. Major goals are reusability and testability: Unnecessary container or framework dependencies can be considered avoidable evils.Of course, Spring's own web support is nicely integrated with the framework's general patterns. Nevertheless, replacing the web solution with Struts, WebWork, or the like is easy. Both with Spring's web support or a different one, Spring allows for building a true dedicated middle tier in the web container, with the option to reuse exactly the same business logic in test environments or standalone applications. And within J2EE, your business logic will not unnecessarily depend on container services like JTA or EJB - allowing complex, well-architected web applications to run in a "simple" container like Tomcat or Resin.Note that Spring doesn't generally aim to compete with existing solutions. It rather fosters seamless integration with standards like Servlet, JSP, JTA, JNDI, JDBC, and JDO, and well-suited tools like Hibernate, Velocity, Log4J, and Caucho's Hessian/Burlap. The framework is designed to grow with the needs of your applications, in terms of technology choice: For example, you will probably use JTA via Spring's JtaTransactionManager if you need distributed transactions - but only then, as there are perfect replacements for single databases, like DataSourceTransactionManager or HibernateTransactionManager.2. Web MVC: The Design of Spring's Web FrameworkSpring's web framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler mappings, view resolution, and locale and theme resolution. The default handler is a very simple Controller interface, just offering a "ModelAndView handleRequest(request,response)" method. This can already be used for application controllers, but you will prefer the included implementation hierarchy, consisting of AbstractController, AbstractCommandController, MultiActionController, SimpleFormController, AbstractWizardFormController. Application controllers will typically be subclasses of those. Note that you can choose an appropriate base class: If you don't have a form, you don't need a FormController. This is a major difference to Struts.You can take any object as command or form object: There's no need to implement an interface or derive from a base class. Spring's data binding is highly flexible, e.g. it treats type mismatches as validation errors that can be evaluated by the application, not as system errors. So you don't need to duplicate your business objects' properties as Strings in your form objects, just to be able to handle invalid submissions, or to convert the Strings properly. Instead, it's often preferable to bind directly to your business objects. This is another major difference to Struts which is built around required base classes like Action and ActionForm - for every type of action. Compared to WebWork, Spring has more differentiated object roles: It supports the notion of a Controller, an optional command or form object, and a model that gets passed to the view. The model will normally include the command or form object but also arbitrary reference data. Instead, a WebWork Action combines all those roles into one single object. WebWork does allow you to use existing business objects as part of your form, but just by making them bean properties of the respective Action class. Finally, the same Action instance that handles the request gets used for evaluation and form population in the view. Thus, reference data needs to be modelled as bean properties of the Action too. These are arguably too many roles in one object.Regarding views: Spring's view resolution is extremely flexible. A Controller implementation can even write a view directly to the response, returning null as ModelAndView. In the normal case, a ModelAndView instance consists of a view name and a model Map, containing bean names and corresponding objects (like a command or form, reference data, etc). View name resolution is highly configurable, either via bean names, via a properties file, or via your own ViewResolver implementation. The abstract model Map allows for complete abstraction of the view technology, without any hassle: Be it JSP, Velocity, or anything else - every renderer can be integrated directly. The model Map simply gets transformed into an appropriate format, like JSP request attributes or a Velocity template model.3. Integration: Using a Different Web Framework with SpringMany teams will try to leverage their investments in terms of know-how and tools, both for existing projects and for new ones. Concretely, there are not only a large number of books and tools for Struts but also a lot of developers that have experience with it. Thus, if you can live with Struts' architectural flaws, it can still be a viable choice for the web layer. The same applies to WebWork and other web frameworks. If you don't want to use Spring's web MVC but intend to leverage other solutions that Spring offers, you can integrate the web framework of your choice with Spring easily. Simply start up a Spring root application context via its ContextLoaderListener, and access it via its ServletContext attribute (or Spring's respective helper method) from within a Struts or WebWork action. Note that there aren't any "plugins" involved, therefore no dedicated integration: From the view of the web layer, you'll simply use Spring as a library, with the root application context instance as entry point. All your registered beans and all of Spring's services can be at your fingertips even without Spring's web MVC. Spring doesn't compete with Struts or WebWork in this usage, it just addresses the many areas that the pure web frameworks don't, from beanconfiguration to data access and transaction handling. So you are able to enrich your application with a Spring middle tier and/or data access tier, even if you just want to use e.g. the transaction abstraction with JDBC or Hibernate.4. Feature Check ListIf just focussing on the web support, some of Spring's unique features are: .Clear separation of roles: controller vs validator vs command object vs form object vs model object, DispatcherServlet vs handler mapping vs view resolver, etc. .Powerful and straightforward configuration of both framework and application classes as JavaBeans, including easy in-between referencing via an application context, e.g. from web controllers to business objects and validators. .Adaptability, non-intrusiveness: Use whatever Controller subclass you need (plain, command, form, wizard, multi action, or a custom one) for a given scenario instead of deriving from Action/ActionForm for everything. .Reusable business code, no need for duplication: You can use existing business objects as command or form objects instead of mirroring them in special ActionForm subclasses. .Customizable binding and validation: type mismatches as application-level validation errors that keep the offending value, localized date and number binding, etc instead of String-only form objects with manual parsing and conversion to business objects. Customizable handler mapping, customizable view resolution: flexible model transfer via name/value Map, handler mapping and view resolution strategies from simple to sophisticated instead of one single way. Customizable locale and theme resolution, support for JSPs with and without Spring tag library, support for JSTL, support for Velocity without the need for extra bridges, etc. Simple but powerful tag library that avoids HTML generation at any cost, allowing for maximum flexibility in terms of markup code.翻译文稿Spring的web MVC 构架模式Juergen Hoeller1. 介绍:Spring 应用构架当你第一次看到Spring的时候,你一定会说:"哦不,又一种web 构架".这篇文章将告诉你Spring明显区别于其他轻量级application framework, 它将专注于web 的支持,与struts 和webwork有着明显的区别。
毕业设计spring mvc
毕业设计spring mvc毕业设计Spring MVC一、引言在计算机科学与技术领域,毕业设计是学生在大学期间的重要任务之一。
作为一个软件开发项目,毕业设计旨在让学生将所学的理论知识应用到实际项目中,并通过实践来提升自己的技术能力和解决问题的能力。
本文将介绍一个常见的毕业设计主题,即使用Spring MVC框架进行开发。
二、Spring MVC简介Spring MVC是一个基于Java的Web应用开发框架,它采用了Model-View-Controller(MVC)的架构模式,用于构建灵活、可扩展和高效的Web应用程序。
Spring MVC提供了一套强大的功能,包括请求处理、视图解析、数据绑定、表单验证等,使得开发人员可以更加专注于业务逻辑的实现。
三、项目需求分析在进行毕业设计之前,首先需要进行项目需求分析。
这个阶段的目标是明确项目的功能和特性,以便后续的开发工作能够有一个明确的目标。
例如,一个简单的毕业设计项目可以是一个在线图书销售平台,其中包括用户注册、图书浏览、购买和评论等功能。
四、项目架构设计在确定了项目需求之后,接下来需要进行项目架构设计。
项目架构设计是指确定项目的整体结构和组织方式,包括模块划分、数据库设计、系统接口定义等。
在使用Spring MVC进行开发时,可以将项目划分为控制器层、服务层和数据访问层等模块,并使用Spring的依赖注入机制来管理各个模块之间的依赖关系。
五、数据库设计在进行数据库设计时,需要根据项目需求分析的结果来确定数据库的表结构和字段。
例如,在图书销售平台的项目中,可以设计一个用户表、图书表和订单表等。
同时,还需要考虑数据库的性能和安全性等方面的问题,例如使用索引来提高查询效率,使用密码加密算法来保护用户密码等。
六、前端设计在进行前端设计时,可以使用HTML、CSS和JavaScript等技术来实现用户界面。
Spring MVC提供了视图解析器的功能,可以将后端数据与前端页面进行绑定,从而实现动态的Web页面。
Spring Web MVC 架构
Handler Interceptor
PreHandler ( )会在 Controller 处理请求之前被 执行,传回的 boolean 决定是否让 Handler Interceptor 或是 Controller 来处理请求,如果传 回 false ,则接下来的 Interceptor 或 controller 就不处理请求, PostHandler ( )则会在 Controller :处理完请求之后被执行, aftercompletion ( )方法会在 View 绘制完成之后 被执行。 您可以继承 org . springframework . web . serv1et . handler . Hand1erInterceptorAdapter , 它实现了 HandlerInterceptor 接口,您只要针对 必要的方法重新定义
Web.xml
<servlet> <servlet-name>dispatcherServlet</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/mvc-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcherServlet</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping>
MVC设计模式介绍毕业论文外文翻译
技术简介1.MVC设计模式介绍MVC模式是“ Model-View-controller ”的缩写,中文翻译为“模式-试图-控制器”。
MVC应用程序总是由这三个部分组成。
Event导致Controller改变Model或View, 或者同时改变两者。
只要Controller改变了Models的数据或者属性,所有依赖的View 都会自动更新。
类似的,重要Controller改变了View, View会从潜在的Model中获取数据来刷新自己。
MVC模式最早是Smalltalk语言研究团提岀的,应用于交互应用程序中。
Java语言是而向对象语言,很自然的SUN在应用程序事例中就推荐MVC 模式作为开发Web应用的架构模式。
MVC模式是一种架构模式,英实需要英他模式协作完成。
在J2EE 模式目录中,通常采用service to worker模式是新,而service to worker模式可由集中控制器模式,派遣器模式和Page Helper模式组成。
2. Struts2 简介虽然Struts2号称是一个全新的框架,但这仅仅是相对Struts 1而言。
Struts2与Strutsl 相比,确实有很多革命性的改进,但它并不是新发布的新框架。
从某种程度上来讲,Struts2没有继承Strutsl的血统,而是继承WebWork的血统。
Struts2是WebWork的升级,而不是一个全新的框架,因此稳泄性、性能等各方而都有很好的保证:而且吸收了Strutsl和WebWork两者的优势。
Struts2 Action类可以实现一个Action接口,也可实现其他接口,使可选和定制的服务成为可能。
Struts2提供一个ActionSupport基类去实现常用的接口。
Action接口不是必须的,任何有execute标识的POJO对象都可以用作Struts2的Action对象。
Struts2 Action 对象为每一个请求产生一个实例,因此没有线程安全问题。
SpringMVC架构浅析
SpringMVC架构浅析SpringMVC概述 Spring的web框架围绕DispatcherServlet设计。
DispatcherServlet的作⽤是将请求分发到不同的处理器。
Spring的web框架包括可配置的处理器(handler)映射、视图(view)解析、本地化(local)解析、主题(theme)解析以及对⽂件上传的⽀持。
Spring的Web框架中缺省的处理器是Controller 接⼝,这是⼀个⾮常简单的接⼝,仅包含ModelAndView handleRequest(request, response) ⽅法。
可以通过实现这个接⼝来创建⾃⼰的控制器(也可以称之为处理器),但是更推荐继承Spring提供的⼀系列控制器,⽐如AbstractController、AbstractCommandController和SimpleFormController。
注意,需要选择正确的基类:如果没有表单,就不需要⼀个FormController。
这是和Struts的⼀个主要区别。
Spring Web MVC允许使⽤任何对象作为命令对象(或表单对象)- 不必实现某个特定于框架的接⼝或从某个基类继承。
Spring的数据绑定相当灵活,例如,它认为类型不匹配这样的错误应该是应⽤级的验证错误,⽽不是系统错误。
所以你不需要为了保证表单内容的正确提交,⽽重复定义⼀个和业务对象有相同属性的表单对象来处理简单的⽆类型字符串或者对字符串进⾏转换。
这也是和Struts相⽐的另⼀个重要区别,Struts是围绕Action和ActionForm等基类构建的。
和WebWork相⽐,Spring将对象细分成更多不同的⾓⾊:控制器( Controller)、可选的命令对象(Command Object)或表单对象(Form Object),以及传递到视图的模型(Model)。
模型不仅包含命令对象或表单对象,⽽且也可以包含任何引⽤数据。
Spring框架-毕业论文外文文献翻译
外文文献翻译SpringFrameworkSpring is an open source framework, and Spring was launched in 2003 as a lightweight Java development framework created by Rod Johnson.In a nutshell, Spring is a hierarchical, JavaSE/EEfull-stack (one-stop) lightweight open source framework.The powerful JavaBeans based configuration management using the Inversion of Control (IoC) principle makes application components faster and easier.1.facilitate decoupling and simplify developmentThrough the IoC container provided by Spring, we can control dependencies between objects by Spring, avoiding excessive program coupling caused by hard coding.With Spring, users do not have to write code for the bottom tier requirements of single instance schema classes, properties, file parsing, and so on, and can focus more on top tier applications.2.AOP programming supportThrough the Spring functionality provided by AOP, it is easy to implement face oriented programming, and many features that are not easily implemented with traditional OOP can be easily handled by AOP.3.declarative transaction supportIn Spring, we can extricate ourselves from tedious and tedious transaction management code and flexibly manage the transaction through declarative manner, so as to improve the efficiency and quality of development.4.convenience program testingAlmost all test work can be done in a non container dependent programming manner, and in Spring, testing is no longer expensive, but something to do.For example, Spring supports Junit4 and can easily test Spring programs by annotations.5.convenient integration of various excellent frameworkSpring does not exclude all kinds of excellent open source framework, on the contrary, Spring can reduce the difficulty of the use of Spring framework, provides a framework for a variety of excellent (such as Struts, Hibernate, Hessian, Quartz) directly support the.6.reduce the difficulty of using Java EE APISpring provides a thin layer of encapsulation for many difficult Java, EE, API (such as JDBC, JavaMail, remote calls, etc.), and the use of these Java EE API is greatly reduced through the simple package of Spring.7.Java source code is a classic example of learningSpring source code, clear structure, exquisite design originality, embodies the master of the Java design pattern and the flexible use of Java technology accomplishment.Spring framework source code is undoubtedly the best practice example of Java technology.If you want to quickly improve your Java skills and application development level in a short time, learning an.The role of MVC - Spring is integration, but not just integration, and the Spring framework can be seen as a framework for enterprise solution levels.The client sends a request, the server controller (implemented by DispatcherServlet) to complete the request forwarding, call a controller for mapping class HandlerMapping, the class is used to map requests to the corresponding processor to process the request.HandlerMapping will request is mapped to the corresponding processor Controller (equivalent to Action) in Spring if you write some processor components, the general implementation of the Controller interface in Controller, you can call Service or DAO to operate data from the DAO ModelAndView used to store the retrieved data, some data can also be stored in response to the view.If you want to return the result to the user, it also provides a view of ViewResolver component in Spring framework, the component labeled Controller returns according to, find the corresponding view, the response response back to the user.Each module (or component) that makes up the Spring framework can exist alone, or can be implemented in conjunction with one or more other modules.Each module has the following functions: 1, the core container: the core container provides the basic functionality of the Spring framework (Spring, Core).The main component of the core container is BeanFactory, which is implemented in factory mode.BeanFactory uses the control inversion (IOC) pattern to separate application configuration and dependency specifications from theactual application code.Spring框架Spring是一个开源框架, Spring是于2003 年兴起的一个轻量级的Java 开发框架, 由Rod Johnson创建。
Spring框架的MVC设计模式是什么
Spring框架的MVC(Model-View-Controller)设计模式是一种软件设计模式,用于将应用程序的业务逻辑、数据处理和用户界面分离,使得代码更加清晰、可维护和可扩展。
在Spring MVC中,应用程序被分为三个核心组件:Model(模型)、View(视图)和Controller(控制器)。
1.Model(模型):模型是应用程序的数据和业务逻辑的表示。
它负责处理数据的读取、存储和操作,以及业务规则的处理。
在Spring MVC中,模型通常是一个Java对象(JavaBean),它包含了应用程序的数据和业务逻辑。
模型对象可以被多个视图和控制器共享和重用。
2.View(视图):视图是用户界面的呈现部分,负责展示数据给用户,并接收用户的输入。
在Spring MVC中,视图通常是一个JSP(JavaServerPages)页面或Thymeleaf模板等,它根据模型的数据进行渲染和展示。
视图不直接处理业务逻辑或数据访问,而是依赖于模型和控制器来提供数据和交互逻辑。
3.Controller(控制器):控制器是模型和视图之间的协调者,负责接收用户的输入并根据输入调用相应的模型逻辑。
在Spring MVC中,控制器通常是一个Java类,它使用注解(如@Controller、@RequestMapping等)来映射URL请求到特定的处理方法。
控制器将用户的请求转发给模型进行处理,并将处理结果传递给视图进行展示。
Spring MVC的设计模式使得应用程序的组件之间解耦,每个组件只关注自己的职责,从而提高了代码的可读性、可维护性和可扩展性。
同时,Spring框架提供了丰富的支持,包括自动配置、依赖注入、异常处理等功能,使得开发者能够更快速地构建健壮的Web应用程序。
Web框架介绍-SpringMVC
Web框架介绍---SpringMVC12.1Web框架介绍Spring 的web框架是围绕分发器(DispatcherServlet)设计的,DispatcherServlet将请求分发到不同的处理器,框架还包括可配置的处理器映射,视图解析,本地化,主题解析,还支持文件上传。
缺省的处理器是一个简单的控制器(Controller)接口,这个接口仅仅定义了ModelAndView handleRequest(request,response)方法。
你可以实现这个接口生成应用的控制器,但是使用Spring提供的一系列控制器实现会更好一些,比如AbstractController,AbstractCommandController,和SimpleFormController。
应用控制器一般都从它们继承。
注意你需要选择正确的基类:如果你没有表单,你就不需要一个FormController。
这是和Structs的一个主要区别。
你可以使用任何对象作为命令对象或表单对象:不必实现某个接口或从某个基类继承。
Spring的数据绑定相当灵活,例如,它认为类型不匹配这样的错误应该是应用级的验证错误,而不是系统错误。
所以你不需要为了处理无效的表单提交,或者正确地转换字符串,在你的表单对象中用字符串类型重复定义你的业务对象属性。
你应该直接绑定表单到业务对象上。
这是和Struts 的另一个重要不同,Struts是围绕象Action和ActionForm这样的基类构建的,每一种行为都是它们的子类。
和WebWork 相比,Spring将对象细分成不同的角色:它支持的概念有控制器(Controller),可选的命令对象(Command Object)或表单对象(Form Object),以及传递到视图的模型(Model)。
模型不仅包含命令对象或表单对象,而且也包含任何引用数据。
但是,WebWork的Action将所有的这些角色都合并在一个单独的对象里。
SpringWebMVC框架简介-最全的介绍
SpringWebMVC框架简介-最全的介绍21. Web MVC框架21.1 Spring Web MVC框架简介Spring Web模型- 视图- 控制器(MVC)框架是围绕一个DispatcherServlet派发请求处理程序,具有可配置的处理程序映射,视图分辨率,区域设置,时区和主题解析以及支持上载文件的。
默认处理程序是基于@Controller和@RequestMapping 注释,提供了广泛的灵活的处理方法。
随着Spring 3.0的推出,该@Controller机制还允许您通过@PathVariable注释和其他功能创建RESTful Web站点和应用程序。
“Open for extension ...”Spring Web MVC和Spring中的一个关键设计原则是“ Open for extension,closed for modification ”原则。
Spring Web MVC的核心类中的一些方法被标记final。
作为一名开发人员,您无法重写这些方法来提供您自己的行为。
这不是任意的,而是专门针对这一原则。
有关这个原理的解释,请参阅Seth Ladd等人的Expert Spring Web MVC和Web Flow ; 具体请参阅第一版117页的“设计看看”一节。
或者,看•鲍勃·马丁,开放原则(PDF)当您使用Spring MVC时,不能将建议添加到最终方法中。
例如,您不能向该AbstractController.setSynchronizeOnSession()方法添加建议。
请参阅第10.6.1节“了解AOP代理”以获取有关AOP代理的更多信息,以及为什么不能将建议添加到最终方法。
在Spring Web MVC中,可以使用任何对象作为命令或形式支持对象; 您不需要实现特定于框架的接口或基类。
Spring的数据绑定非常灵活:例如,它将类型不匹配视为可由应用程序评估的验证错误,而不是系统错误。
SpringMVC框架介绍
SpringMVC框架介绍⼀、什么是 SpringMVC ?SpringMVC框架是以请求为驱动,围绕Servlet设计,将请求发给控制器,然后通过模型对象,分派器来展⽰请求结果视图。
其中核⼼类是,它是⼀个Servlet,顶层是实现的Servlet接⼝。
在介绍什么是 SpringMVC 之前,我们先看看 Spring 的基本架构。
如下图: 我们可以看到,在 Spring 的基本架构中,红⾊圈起来的 Spring Web MVC ,也就是本系列的主⾓ SpringMVC,它是属于Spring基本架构⾥⾯的⼀个组成部分,属于SpringFrameWork的后续产品,已经融合在Spring Web Flow⾥⾯,所以我们在后期和 Spring 进⾏整合的时候,⼏乎不需要别的什么配置。
SpringMVC 是类似于 Struts2 的⼀个 MVC 框架,在实际开发中,接收浏览器的请求响应,对数据进⾏处理,然后返回页⾯进⾏显⽰,但是上⼿难度却⽐ Struts2 简单。
⽽且由于 Struts2 所暴露出来的安全问题,SpringMVC 已经成为了⼤多数企业优先选择的框架。
⼆、SpringMVC流程图详解要把SpringMVC流程图搞明⽩,⾸先需要先搞明⽩6个组件 1.DisPatcherServlet 前端控制器核⼼。
⽤户在浏览器输⼊url,发起请求,⾸先会到达DisPatcherServlet,由它来调⽤其他组件来配合⼯作的完成,DisPatcherServlet的存在⼤⼤降低了组件之间的耦合性2.HandlerMapping 处理器映射器记录url与处理器的映射,⽅式有注解、XML配置等3.HandLer 处理器后端控制器(通俗⼀点:Controller层所写的业务代码)。
对⽤户的请求进⾏处理4.HandlerAdapter 处理器适配器通过HandlerAdapter对处理器进⾏执⾏,这是适配器模式的应⽤,通过扩展适配器可以对更多类型的处理器进⾏执⾏。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
翻译文稿1:Spring的web MVC 构架模式Juergen Hoeller1.介绍:Spring 应用构架当你第一次看到Spring的时候,你一定会说:"哦不,又一种web 构架".这篇文章将告诉你Spring明显区别于其他轻量级application framework, 它将专注于web的支持,与struts 和 webwork有着明显的区别。
在和struts 和 webwork的对比上,Spring是一个服务于所有层面的application framework:提供了bean的配置基础,AOP的支持,JDBC的提取框架,抽象事务支持,等等。
它有一个非常显著的特点:在某个层面上如果你不需要Spring的支持,你就可以不使用String的class,只使用它的某一部分的功能。
从它的设计理念,你可以看到String 帮助你实现了真正的逻辑层和web层的分离:例如。
一个校验应用将不用依靠controllers,就可以实现。
这样的目标是更好的重用和易测:过分依靠不必要的容器和框架将不能实现这一点。
当然,Spring 的自己的web支持和通常框架模式的细致完整.然而,Spring 替换struts,webwork或者其他的web方案非常的容易.对于Spring的web支持或者不同的地方,Spring 允许你在web容器里面建立一个中间层,在测试环境或者标准独立的应用里面来设置重用你的商务逻辑.还有在J2EE环境里面,你的商务逻辑不必依靠容器提供的服务,像JTA ,EJB的支持.良好的构架的web应用可以运行在任何容器上,如,Tomcat 或者 Resin. 值得注意的是,Spring 不是和已经存在的解决方案进行竞争. 我们鼓励结合标准的技术,如,Servlet, JSP, JTA, JNDI, JDBC, and JDO, 和非常匹配的工具,如,Hibernate, Velocity, Log4J, and Caucho's Hessian/Burlap.这个框架的的设计思想是在你的应用需要改良的时候,你将会做一些技术的选择:例如,如果你需要分布式事务处理,你可能需要用Spring的Jta TransactionManager 来实现JTA服务.或者,用DataSourceTransactionManager or HibernateTransactionManager 来实现美妙完美的单个数据库交换。
2. Web MVC:Spring web 框架的设计思想Spring 框架通过配置操作mappings,展示resolution,本地化和模版集成围绕着分派请求操作的servlet - DispatcherServlet设计的.缺省的操作是一个非常简单的控制接口, 他只提供了ModelAndViewhandleRequest(request,response)方法.这将用于一个应用的控制,但是,如果你想包含多个层次的控制,AbstractController, AbstractCommandController, MultiActionController, SimpleFormController, AbstractWizardFormController 将帮助你完成.应用控制将代表那些子系统.注意,你可以选择一个适当的基类:如果你没有 web form,你就不必用FormController.这就是和Struts最大的不同. 你可以通过命令或者form对象来操作任何对象:这不需要接口工具或者一个基础类的驱动.Spring的数据邦定是非常的灵活的.举例来说,它描述了具有在应用范围内的校验错误的输入机制,但不是系统错误.所以在你的form对象里面你不必复制你的业务对象的string属性,只操作出错的子任务,或者适当地转换string.换句话说,它通常可以很好的直接邦定你的业务对象. 这也是和struts围绕请求基础类Action 和 ActionForm (每个action操作类型) 建立主要的不同之一. 对比WebWork,Sping更多的区别在于对象角色:Sping支持控制器的感念,一个操作命令或者form对象,和得到数据传递给视图的模式.这个模式通常包含命令和form对象,但有时也包含任意的参考数据.换句话说,一个WebWork Action联合所有这些角色到一个单独的对象.WebWork 允许你用已经存在的业务对象作为你 form 的一部分,但是只生成各自Action 的 bean 属性. 最后,操作请求的Action 实例在一个视图里面获得付值和form population. 然而,参考数据也需要作为Action 的属性被模拟. 一个类里面有太多的角色是值得讨论的. 关于视图:Spring的视图方案非常的灵活. 一个控制器执行可以通过response 返回ModelAndView对象null,就可以直接写到一个视图.在通常的状况下,一个ModelAndView实例结合了一个view 和一个 model Map,包含了bean name 和通讯对象(像命令或者form,参考数据等等). View名称是非常高端的的配置,不是通过bean name, 一个properties 文件就是通过你自己的ViewResolver.这个抽象的model Map 允许你在视图层面完成提取,没有任何的争辩JSP/Velocity或者其他,每一种都可以直接完整使用.这个model Map 还可以简单得得到适当的格式化数据的转换,像JSP 请求属性或者Velocity 模版模式.3.集成:用Spring一个不同web 框架许多开发团队将为他们已有的项目或者新的项目已经获得的期限和工具进行投资.这里没有像Struts那样大量的图书和工具,但是同样我们有大量的拥有Spring开发技巧的开发人员.然而,如果你愿意生活在Struts的构架瑕疵中的话,他将是你在web层开发不错的选择.当然,其他应用也是一样. 如果你不想用Spring的 web MVC ,但是想借用Spring嫁接其他的解决方案,你可以非常简单地通过Spring 继承你自己的web 框架.你可以非常简单地通过ContextLoaderListener 启动一个Spring root application context, 并且,通过Struts 或者WebWork 的action 利用ServletContext 属性(或者Spring 的helper方法)存取它. 值得注意的是, 这里没有任何的 "plugins"被调用,因此没有专门的集成:来自web层的视图, 你可以简单的将Spring作为一个管理application context 实例入口点的类库. 所有你注册bean和Spring服务都可以在不需要Spring的web MVC的情况下都可以被你轻松掌握.Spring 不是和Struts ,WebWork这些应用进行竞争,它将作为一个纯web框架应用于很多领域,因为它不需要配置数据存储和事务操作.所以,你可以利用Spring提供的中间层和数据存储层来丰富你的应用,甚至,你想用JDBC或者Hibernate进行事务抽象.4.特点核对列表如果聚焦于web 支持,Spring的一些显著特点是: 清楚地角色分离:controller , validator , command object , form object , model object,和 DispatcherServlet , handler mapping vs view resolver, 等等强大而且直接的框架和作为JavaBeans的应用配置,包括简单的参照和应用内容,例如,从web控制器到业务对象和数据校验. 适应性,外挂:无论什么样的控制器你都需要得到代替Action/ActionForm所做的每件事情的方案(简单,命令,form,范例,多重action,或者定制一个) 重用业务逻辑代码,不需要复制:你可以用已经有的业务逻辑对象作为命令或则form对象代替反射特定的ActionForm子类. 可订制的邦定和数据校验:作为应用级的输入机制的错误校验,固定日期和数字邦定,例如,通过手动检查和转换业务对象来替换单个的string。
可订制的操作,可订制的视图方案:通过name/value Map灵活的模型传送,用一个简单的方法从简单到复杂操作映射和视图方案策略.本地定制和主题方案:Spring没有taglib,完全支持于JSPs,JSTL,不需要额外的连接就可以支持Velocity,等等. 简单但是强大的tag library避免了HTML产生的混乱,最大限度的灵活扩展了标记代码.翻译文稿2:一种基于Hibernate和Struts的J2EE应用开发策略本文分析了Hibernate和Struts的机制,提出了一种基于Hibernate和Struts的J2EE应用开发策略。
在这种策略中,模型层用Hibernate实现,视图和控制器则用Struts框架实现。
这样可大大降低代码的耦合性以及提高系统的开发效率。
关键字 Hibernate,Struts,MVC,持久层1 引言随着Java技术的逐渐成熟与完善,作为建立企业级应用的标准平台,J2EE 平台得到了长足的发展。
借助于J2EE规范中包含的多项技术:Enterprise JavaBean(EJB)、Java Servlets(Servlet)、Java Server Pages(JSP)、Java Message Service(JMS)等,开发出了许多应用系统。
但是,在传统J2EE应用的开发过程中也出现了一些问题:1)数据模型和逻辑模型之间的矛盾。
目前使用的数据库基本上都是关系型数据库,而Java本质上是一种面向对象的语言,对象在存储和读取时使用SQL和JDBC进行数据库操作,降低了编程的效率以及系统的可维护性;2)传统的J2EE应用多采用基于EJB的重量级框架,这种框架适合于开发大型企业应用,但是使用EJB容器进行开发和调试需要耗费大量时间。
为了降低代码的耦合性,提高系统的开发效率,本文提出了一种基于Struts框架和Hibernate框架的J2EE应用开发策略。
2 数据持久层及Hibernate Hibernate是一个数据持久层框架,是一种实现对象和关系之间映射(O/R Mapping)的工具,它对JDBC进行了轻量级的对象封装,使程序员可以使用对象编程思想来操作数据库。
它不仅提供了从Java类到数据表的映射,也提供了数据查询和恢复机制。