The Spring web MVC framework provides model-view-controller architecture and ready…
- User
The Spring web MVC framework provides model-view-controller architecture and ready components that can be used to develop flexible and loosely coupled web applications. The MVC pattern results in separating the different aspects of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements. The Model encapsulates the application data and in general they will consist of POJO. The View is responsible for rendering the model data and in general it generates HTML output that the client's browser can interpret. The Controller is responsible for processing user requests and building appropriate model and passes it to the view for rendering. A. The Dispatcher Servlet The Spring Web model-view-controller (MVC) framework is designed around a DispatcherServlet that handles all the HTTP requests and responses. The request processing workflow of the Spring Web MVC DispatcherServlet is illustrated in the diagram:Following is the sequence of events corresponding to an incoming HTTP request to DispatcherServlet: After receiving an HTTP request, DispatcherServlet consults the HandlerMapping to call the appropriate Controller. The Controller takes the request and calls the appropriate service methods based on used GET or POST method. The service method will set model data based on defined business logic and returns view name to the DispatcherServlet. The DispatcherServlet will take help from ViewResolver to pickup the defined view for the request. Once view is finalized, The DispatcherServlet passes the model data to the view which is finally rendered on the browser. All the above mentioned components i.e.HandlerMapping, Controller and ViewResolver are parts of WebApplicationContext which is an extension of the plain ApplicationContext with some extra features necessary for web applications.You need to map requests that you want the DispatcherServlet to handle, by using a URL mapping in the web.xml file. Defining a Controller - DispatcherServlet delegates the request to the controllers to execute the functionality specific to it. The @Controller annotation indicates that a particular class serves the role of a controller. The @RequestMapping annotation is used to map a URL to either an entire class or a particular handler method. The @Controller annotation defines the class as a Spring MVC controller. Creating JSP Views - Spring MVC supports many types of views for different presentation technologies. These include - JSPs, HTML, PDF, Excel worksheets, XML, Velocity templates, XSLT, JSON, Atom and RSS feeds, JasperReports etc. But most commonly we use JSP templates written with JSTL.帮我翻译成中文
- Assistant
Spring Web MVC 框架提供了模型-视图-控制器架构和可用于开发灵活和松散耦合的 Web 应用程序的准备组件。MVC 模式可将应用程序的不同方面(输入逻辑、业务逻辑和 UI 逻辑)分离,同时在这些元素之间提供松散耦合。 模型封装了应用程序数据,通常由 POJO 组成。 视图负责呈现模型数据,通常生成客户端浏览器可以解释的 HTML 输出。 控制器负责处理用户请求并构建适当的模型,将其传递给视图进行呈现。 A. DispatcherServlet Spring Web MVC 模型 - 视图 - 控制器框架的设计围绕一个 DispatcherServlet 进行,该 Servlet 处理所有 HTTP 请求和响应。Spring Web MVC DispatcherServlet 的请求处理工作流程如下所示: 在收到 HTTP 请求后,DispatcherServlet会咨询 HandlerMapping 来调用适当的 Controller。 控制器接受请求,并根据使用的 GET 或 POST 方法调用相应的服务方法。服务方法将基于定义的业务逻辑设置模型数据并返回视图名称给 DispatcherServlet。 DispatcherServlet 将会在 ViewResolver 的帮助下选择定义的视图。 确定了视图后,DispatcherServlet 将模型数据传递给视图,最终在浏览器上呈现。 上述所有组件,包括 HandlerMapping、Controller 和 ViewResolver,都是 WebApplicationContext 的一部分,WebApplicationContext 是 ApplicationContext 的扩展,具有适用于 Web 应用程序所需的一些额外功能。您需要使用 web.xml 文件中的 URL 映射来映射您希望 DispatcherServlet 处理的请求。 定义控制器:DispatcherServlet 委派请求来执行特定于其的功能的控制器。@Controller 注释表示特定类充当控制器的角色。@RequestMapping 注释用于将 URL 映射到整个类或特定处理程序方法。@Controller 注释将类定义为 Spring MVC 控制器。 创建 JSP 视图:Spring MVC 支持许多不同的视图类型,适用于不同的呈现技术。这些视图包括——JSP、HTML、PDF、Excel 工作表、XML、Velocity 模板、XSLT、JSON、Atom 和 RSS 订阅、JasperReports 等。但通常我们使用使用 JSTL 编写的 JSP 模板。
- User
Spring is a powerful framework that solves many common problems in J2EE. Many Spring features are also usable in a wide range of Java environments, beyond classic J2EE. Spring provides a consistent way of managing business objects and encourages good practices such as programming to interfaces, rather than classes. The architectural basis of Spring is an Inversion of Control container based around the use of JavaBean properties. However, this is only part of the overall picture: Spring is unique in that it uses its IoC container as the basic building block in a comprehensive solution that addresses all architectural tiers. Spring provides a unique data access abstraction, including a simple and productive JDBC framework that greatly improves productivity and reduces the likelihood of errors. Spring's data access architecture also integrates with TopLink, Hibernate, JDO and other O/R mapping solutions. Spring also provides a unique transaction management abstraction, which enables a consistent programming model over a variety of underlying transaction technologies, such as JTA or JDBC. Spring provides an AOP framework written in standard Java, which provides declarative transaction management and other enterprise services to be applied to POJOs or - if you wish - the ability to implement your own customaspects. This framework is powerful enough to enable many applications to dispense with the complexity of EJB, while enjoying key services traditionally associated with EJB.帮我翻译成中文
- Assistant
Spring 是一个强大的框架,解决了许多 J2EE 中的常见问题。许多 Spring 功能也可在广泛的 Java 环境中使用,不仅限于经典的 J2EE。 Spring 提供了一致的管理业务对象的方式,并鼓励良好的实践,例如编程到接口,而不是类。Spring 的架构基础是围绕使用 JavaBean 属性的控制反转容器。然而,这只是整个图片的一部分:Spring 是独特的,因为它使用其 IoC 容器作为解决所有架构层的全面解决方案的基本构建块。 Spring 提供独特的数据访问抽象,包括简单且高效的 JDBC 框架,大大提高了生产力,减少了错误的可能性。Spring 的数据访问架构还与 TopLink、Hibernate、JDO 和其他 O/R 映射解决方案集成。 Spring 还提供了独特的事务管理抽象,可在各种底层事务技术上实现一致的编程模型,例如 JTA 或 JDBC。 Spring 提供了一个用标准 Java 编写的 AOP 框架,提供声明式事务管理和其他企业服务可以应用于 POJO 或 - 如果您希望 - 实现自定义切面的能力。这个框架足够强大,能够使许多应用程序摆脱 EJB 的复杂性,同时享受传统上与 EJB 相关的关键服务。