1, the configuration of the head profile springmvc:
1 <beans xmlns="http://www.springframework.org/schema/beans" 2 xmlns:mvc="http://www.springframework.org/schema/mvc" 3 xmlns:context="http://www.springframework.org/schema/context" 4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 5 xsi:schemaLocation=" 6 http://www.springframework.org/schema/beans 7 http://www.springframework.org/schema/beans/spring-beans.xsd 8 http://www.springframework.org/schema/context 9 http://www.springframework.org/schema/context/spring-context.xsd 10 http://www.springframework.org/schema/mvc 11 http://www.springframework.org/schema/mvc/spring-mvc.xsd">
the maven pom-dependent configuration file is introduced:
1 <properties> 2 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 3 <maven.compiler.source>1.7</maven.compiler.source> 4 <maven.compiler.target>1.7</maven.compiler.target> 5 <!--版本锁定--> 6 <spring.version>5.0.7.RELEASE</spring.version> 7 </properties> 8 9 <dependencies> 10 <dependency> 11 <groupId>org.springframework</groupId> 12 <artifactId>spring-context</artifactId> 13 <version>${spring.version}</version> 14 </dependency> 15 16 <dependency> 17 <groupId>org.springframework</groupId> 18 <artifactId>spring-web</artifactId> 19 <version>${spring.version}</version> 20 </dependency> 21 22 <dependency> 23 <groupId>org.springframework</groupId> 24 <artifactId>spring-webmvc</artifactId> 25 <version>${spring.version}</version> 26 </dependency> 27 28 <dependency> 29 <groupId>javax.servlet</groupId> 30 <artifactId>servlet-api</artifactId> 31 <version>2.5</version> 32 </dependency> 33 </dependencies>
2, when used in web.xml configure a front-end controller (servlet), and the spring in the servlet configuration file into fixed :()
1 <servlet> 2 <servlet-name>dispatcherServlet</servlet-name> 3 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 4 <init-param> 5 <param-name>contextConfigLocation</param-name> 6 <param-value>classpath:springMVC.xml</param-value> 7 </init-param> 8 </servlet> 9 <servlet-mapping> 10 <servlet-name>dispatcherServlet</servlet-name> 11 <url-pattern>/</url-pattern> 12 </servlet-mapping>
3, controller layer SpringMVC the servlet is not employed as the rear end of the control, but the use of
@ Controller, @ RequestMapping ( "Login") annotation to make a Java class as a controller.
Supplementary: @RequestMapping (value = "/") is the mapping method into a "servlet", by the access method to the url.
. 1 @Controller 2 public class helloSpringMVC { . 3 @RequestMapping (value = "/ Hello" ) . 4 public String sayHello () { . 5 System.out.println ( "This is the first program springMVC" ); . 6 return "Success" ; 7 } 8 }
4, the spring profile, initialize the view parser for processing the content for the page returned by the return jump
Key Tags: InternalResourceViewResolver,
. 1 < the bean ID = "InternalResourceViewResolver" class = "org.springframework.web.servlet.view.InternalResourceViewResolver" > 2 < Property name = "prefix" value = "/ Pages /" > </ Property > // jump page Contents 3 < Property name = "suffix" value =. "JSP" /> // jump file extension 4 </ bean >
5, open framework annotation support springMVC
<mvc:annotation-driven/>