1. Preface
Recently in a test system, the front desk is SPRINGMVC architecture, so I intend to write a few blogs to summarize the knowledge about SPRINGMVC. I remember using the. NET version of the MVC framework before, so the overall understanding is not very difficult.
The overall architecture of the 2.SpringMVC
2.1 Overall flowchart
2.2 SPRINGMVC Structure
Look at the above flowchart, the following simple analysis.
Dispatcherservlet: A central controller that forwards requests to a specific controller class
Controller: The control that specifically handles the request
Handlermapping: Mapping processor, responsible for mapping the central processing unit forwarded to the specific controller
Modelandview: wrapper class for data and view layers returned by the service layer
Viewresolver: View Resolver
Interceptor: Interceptor, responsible for intercepting our defined requests and doing the processing work
3. Explanation of the first example
3.1 Configuring the central controller
<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://java.sun.com/xml/ns/javaee" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee/http Java.sun.com/xml/ns/javaee/web-app_3_0.xsd "id=" webapp_id "version=" 3.0 "><!--Central Transponder--><servlet> <servlet-name>springmvc</servlet-name><servlet-class> Org.springframework.web.servlet.dispatcherservlet</servlet-class></servlet><servlet-mapping> <servlet-name>springmvc</servlet-name><!--//Do not configure/*, or you will receive a 404 error--><url-pattern>*.do< /url-pattern></servlet-mapping><display-name>spring-mvc</display-name></web-app>
3.2 Creating a SPRINGMVC core configuration file
Naming rules for files: Central controller (servlet name) + "-servlet.xml"
Default location: Web-inf
Configuring the Controller and view resolver
<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc= "Http://www.springframework.org/schema/mvc" xmlns: context= "Http://www.springframework.org/schema/context" xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:tx= "Http://www.springframework.org/schema/tx" xsi:schemalocation= "http://www.springframework.org/schema/ Beans Http://www.springframework.org/schema/beans/spring-beans-3.0.xsd Http://www.springframework.org/schema/mvc Http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd Http://www.springframework.org/schema/context http ://www.springframework.org/schema/context/spring-context-3.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http ://www.springframework.org/schema/aop/spring-aop-3.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/TX/http Www.springframework.org/schema/tx/spring-tx-3.0.xsd "><!--configuration file form to configure: Controller,handlermapping (with default rules), Viewresolver,inTerceptor--><bean class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" ><!-- Configure from the project root directory to one end path--><property name= "prefix" value= "/web-inf/jsp/"/><!--file suffix name--><property name= " Suffix "value=". jsp "/></bean><!--configuration Controller,name The path to the controller to be accessed--><bean id=" TestController "name= "/hello.do" class= "Com.url.controller.TestController" ></bean></beans>
3.3 Creating a Controller
Package Com.url.controller;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;import Org.springframework.web.servlet.modelandview;import Org.springframework.web.servlet.mvc.abstractcontroller;public class TestController extends AbstractController {@ overrideprotected Modelandview handlerequestinternal (httpservletrequest arg0,httpservletresponse arg1) throws Exception {System.out.println ("Hello Springmvc");//modelandview is automatically prefixed and suffixed with the View parser resolution return new Modelandview ("Index");}}
4. Summary
This blog simply explains the overall architecture of SPRINGMVC, with a simple example, the next blog to explain how several view mappings.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The first instance of SPRINGMVC