The simple entry SpringMvc

  Here Insert Picture Description


  1. The three-tier architecture: presentation layer (SpringMvc), business layer (Spring), persistence (Mybatis)

  So it simply SpringMvc have do is about:

  Request parameter

  Response results

  2.SpringMvc is based on the MVC design model

  M: model models such as: javaBean

  V: view view as: jsp

  C: controller such as controller: Servlet

  The similarities and differences 3.SpringMVC and struts2 :( interview may be asked)

  Common:

  They are the presentation layer of the MVC model frameworks to write

  They are inseparable from the bottom score ServletAPI

  They request processing mechanism is a core controller (SpringMvc is achieved Servlet Filter Struts2 is realized)

  Similarities and differences:

  SpringMVC entrance is Servlet, and is Struts2 Filter (filter);

  SpringMVC is based on a real design, and struts2 is designed based on class, Struts2 each execution will go to create a class action, so SpringMVC efficiency will be faster than some of Struts2.

  SpringMVC use more concise, and also supports JSR303, more convenient to deal with ajax

  Struts2 development efficiency of OGNL expression is higher compared to SpringMVC page, but did not enhance the efficiency ratio JSTL, especially Struts2 form tags, html is far higher efficiency

  Here Insert Picture Description


  1. Select a template Maven webapp project here will not say, hee hee, a little reminder:

  Plus archetypeCatalog: internal project will solve the problem of slow loading

  2. completion catalog:

  3. Import dependency:

  UTF-8

  1.8

  1.8

  5.1.3.RELEASE

  org.springframework

  spring-context

  ${spring.version}

  org.springframework

  spring-web

  ${spring.version}

  org.springframework

  spring-webmvc

  ${spring.version}

  org.apache.tomcat

  servlet-api

  6.0.29

  org.apache.tomcat

  jsp-api

  6.0.29

  4. The front controller disposed in web.xml

  Archetype Created Web Application

  dispatcherServlet

  org.springframework.web.servlet.DispatcherServlet

  contextConfigLocation

  classpath:springmvc.xml

  1

  dispatcherServlet

  /

  5. Create a springmvc.xml profile on resources under

  6. Configure tomcat, the project came loaded

  Here Insert Picture Description

 Zhengzhou gynecological hospital http://www.120zzkd.com/

  I wrote a index.jsp page, when I click on the tag, I would jump to the inside of a method to perform the function of a Controller, executing the jump to the page success.jsp

  1. First I wrote a method for the Controller class

  I'm writing a tag in index.jsp

  Entry procedures

  When I click on the jump to sayhello () This method inside

  2.1

  First of all I want to become an object of this class HelloController ah, then I by means of the spring configuration file for, plus a @Controller on the class, this time by means of springmvc.xml we just scanned the package, and then create a Spring container, create HelloController object.

  2.2

  Namespaces:

  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"

  xsi:schemaLocation="http://www.springframework.org/schema/beans

  http://www.springframework.org/schema/beans/spring-beans.xsd

  http://www.springframework.org/schema/context

  http://www.springframework.org/schema/context/spring-context.xsd

  http://www.springframework.org/schema/mvc

  http://www.springframework.org/schema/mvc/spring-mvc.xsd">

  OnScan

  2.3

  At this comment @RequestMapping ( "/ hello") on whether you noticed sayhello () methods?

  What role does it do?

  It is used to establish the link between the request and process the request URL method:

  With its front controller entry procedures can be found in sayhello HelloController mapper by a processor () method.

  2.4

  Why did you return value is "success" of it, and so I said before you can jump to the implementation of End success.jsp, but how to jump? This SpringMvc of view resolver has to help us solve

  In view resolver arranged in springmvc.xml:

  With the path name, the suffix has also been, I only need to provide the name of a jsp just fine, and the return value sayhello () method defaults to the name of the path, so I can perform a complete page jump to success.jsp .

  2.5

  But in my code can be seen also @RequestMapping (path = "/ user") on HelloController this class, do the class can also add this comment ???

  ! YES on the annotated class is equivalent to a path, the path to access the jsp:

  Entry procedures

  2.6

  SpringMvc framework is composed of individual components, so more flexible.

  SpringMvc various components, the mapping processor, a processor adapter viewresolver referred SpringMvc three components, a teacher on the right in FIG.

  But we can see from this figure, there are other components play a role in it,

  When the only view of the adapter will be configured so that with effect, why do not configure the mapping process and processor adapter ah?

  On the code, hhhhhhhhhhhhhhh

  Is open SpringMvc comments configuration, it defaults to the mapper, adapter configuration, which means that this line of code to make maps, adapters also come into force.


Guess you like

Origin blog.51cto.com/14503791/2460094