1.精确匹配
2.全路径匹配
3.后缀匹配
1.精确匹配
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* 请求映射的第一种方式
* @author xieke
*/
@Controller
@RequestMapping("/test_url_one")
public class TestOneController {
/**
* web.xml中servlet-mapping的配置
* <servlet-mapping>
* <servlet-name>dispatcher</servlet-name>
* <!-- 表示拦截所有/XX的请求 -->
* <url-pattern>/</url-pattern>
* </servlet-mapping>
*
* 请求方式:
* http://IP地址:端口号/项目名称/类请求映射名称/方法请求映射名称
* 比如:
* http://127.0.0.1:1314/SpringMVC_URL/test_url_one/index
*/
@RequestMapping("/index")
public String testOne(){
return "success";
}
}
2.全路径匹配
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* 请求映射的第一种方式
* @author xieke
*/
@Controller
@RequestMapping("/test_url_one")
public class TestOneController {
/**
* web.xml中servlet-mapping的配置
* <servlet-mapping>
* <servlet-name>dispatcher</servlet-name>
* <!-- 表示拦截所有/XX的请求 -->
* <url-pattern>/</url-pattern>
* </servlet-mapping>
*
* 请求方式:
* http://IP地址:端口号/项目名称/类请求映射名称/方法请求映射名称
* 比如:
* http://127.0.0.1:1314/SpringMVC_URL/test_url_one/index
*/
@RequestMapping("/index")
public String testOne(){
return "success";
}
}
3后缀匹配
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* 请求映射的第二种方式
* @author xieke
*/
@Controller
@RequestMapping("/test_url_two")
public class TestTwoController {
/**
* web.xml中servlet-mapping的配置
* <servlet-mapping>
* <servlet-name>dispatcher</servlet-name>
* <!-- 表示拦截所有XX.do的请求 -->
* <url-pattern>*.do</url-pattern>
* </servlet-mapping>
*
* 请求方式:
* http://IP地址:端口号/项目名称/类请求映射名称/方法请求映射名称.do
* 比如:
* http://127.0.0.1:1314/SpringMVC_URL/test_url_two/index.do
*/
@RequestMapping("/index")
public String testTwo(){
return "success";
}
}
转载:http://xieke90.iteye.com/blog/2235706