博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring MVC: Some notes
阅读量:4973 次
发布时间:2019-06-12

本文共 4018 字,大约阅读时间需要 13 分钟。

The following notes are based on the article "", which is, though, a little bit old, but very helpful for beginners, like me. 

 

The MVC Framework landscape

Besides Spring MVC, there are also some other frameworks, like Structs, Wicket, JavaSerer Faces(JSF), Seam, etc.

A breif history about Java Web Applications

  • In 1997, the  was introduced.

With servlets, dynamically constructing HTML documents became easy. But because the documents were constructed inside Java source code, maintenance was challenging.

  • In 1999, Sun resolved this issue by introducing (JSP)

Rather than implementing presentation code inside servlets, JSPs let you build HTML-like documents that interweave snippets of Java code to support dynamic content. At runtime, JSPs are translated to servlet source code, compiled, and then deployed to a Web container dynamically.

This architecture was called page-driven or Model 1. 

In page-driven applications, each page not only contains the business logic required to generate the dynamic content, but also the control logic  to determine application flow.

  • The solution was to separate programmatic responsibilities into the technologies best suited for them.

Thus was born the architecture, which adheres to the MVC Smalltalk design pattern:

  1. The model represents your data or the objects with which your application is interacting. (POJO, etc)
  2. The view is a visualization of your model. (JSP, etc)
  3. The controller manages application flow and make calls into business objects. (Servlet, etc)

In a Spring MVC architecture, you implement controllers that make calls into Spring service beans to perform business actions and then send a model object to one of your views for presentation. 

 

Spring: An overview

Key benifit of Spring is dependency injection, which is a desin patten coined by Martin Fowler, that separates an application's dependencies (and dependency configuration) from the code that uses those dependencies. 

 

Introducing Spring MVC

Spring provides a front controller servlet named DispatcherServlet. To build an application, you construct the following components:

  • One or more controllers that invoke business logic and create a ModelAndView object
  • A visualization components such as a JSP
  • XML or annotation configuration to wire the compoments together.

 Spring provides various controllers to use as base classes for creating your own controllers, like

  • Redirect to static views
  • Provide basic servlet-like functionality
  • Process commands
  • Process shared actions
  • Handle forms
  • Provide wizard-like functionality to process multipage forms

 

The primary entry point for a Spring application is the DispatcherServlet, so the first step is create a DispatcherServlet in the web.xml file:

geeknews
org.springframework.web.servlet.DispatcherServlet
1

Next, the DispatcherServlet needs to be mapped to a URI pattern.

geeknews
*.htm

 

There are some URL mapping beans to translate a URL pattern to a controller,

  • BeanNameUrlHandlerMapping: Maps a URL to a bean based on the name of the controller's bean, as defined in the bean's XML definition.
  • SimpleUrlHandlerMapping: Maps a URL to a bean based on a list of properties. (In Listing 2, the SimpleUrlHandlerMapping class is used to map /home.htm to the bean with the ID of homePageController.)
  • ControllerClassNameHandlerMapping: Maps a URL to a bean based on the bean's class name. For example, HomePageController would be mapped to /homePage*, such as /home.htm.
  • ControllerBeanNameHandlerMapping: Similar to the BeanNameUrlHandlerMapping mapper, but does not expect bean names to follow the URL convention. Also supports Controller annotations.
  • CommonsPathMapHandlerMapping: Maps URLs to a controller based on Jakarta Commons Attributes metadata.
  • DefaultAnnotationHandlerMapping: Maps URLs to a controller for methods that implement the RequestMapping annotation.

 

 

转载于:https://www.cnblogs.com/fangwenyu/archive/2012/10/11/2717594.html

你可能感兴趣的文章
MFC编程入门之八(对话框:创建对话框类和添加控件变量)
查看>>
MACD各分时背离所对应的时间
查看>>
werkss 的 人工智能程序开发理论框架
查看>>
spring注解 @Scheduled(cron = "0 0 1 * * *")的使用来实现定时的执行任务
查看>>
企业实施CRM系统带来的一些好处
查看>>
ant 使用指南
查看>>
PHP数组
查看>>
DS-5/RVDS4.0变量初始化错误
查看>>
簡單SQL存儲過程實例
查看>>
css basic
查看>>
GCC编译警告和错误
查看>>
Spring 笔记
查看>>
变量定义规范
查看>>
死锁的形成以及处理
查看>>
Spring Boot的三种启动方式
查看>>
转:storm中一个Bolt发emit多次相同类型消息
查看>>
MySql行列转换方法自我总结
查看>>
查询归档量
查看>>
搜索引擎营销入门
查看>>
#leetcode刷题之路25- k个一组翻转链表
查看>>