1.maven依赖
org.springframework
spring-webmvc
5.0.5.RELEASE
2.web.xml(在web.xml里面配置DispatcherServlet,可以配置多个)
/p>
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
app1
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
WEB-INF/app1.xml
1
app1
/
3.DispatcherServlet的配置,默认名字为 {servlet-name}-servlet .xml,可以在里面配置DispatcherServlet的具体细节。
配置的是DispatcherServlet的子上下文。
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-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
4.编写controller
package com.warofcode.springmvc.web;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HelloController {
@RequestMapping("/app1/hello")
public String hello(){
return "hello";
}
}