标签:spring mvc
继续http://blog.csdn.net/gaopeng0071/article/details/47447811章节,
了解@RequestMapping更多其他用法,查看@RequestMapping参数如图
用法如下
In a Servlet environment: the path mapping URIs (e.g. “/myPath.do”). Ant-style path patterns are also supported (e.g. “/myPath/*.do”). At the method level, relative paths (e.g. “edit.do”) are supported within the primary mapping expressed at the type level.
代码
@RequestMapping(value = "/*/sayHello")
public String sayHello() {
System.out.println("hello world!!!");
return "success";
}
<a href="springMVC/aaa/sayHello.do">Test HelloWorld</a>
The HTTP request methods to map to, narrowing the primary mapping: GET, POST, HEAD, OPTIONS, PUT, DELETE, TRACE.
主要使用GET、POST两种请求方式。
代码
@RequestMapping(value = "/testRequestMethod", method = RequestMethod.POST)
public String testRequestMethod() {
System.out.println("testRequestMethod");
return "success";
}
<form action="springMVC/testRequestMethod.do" method="post">
<input type="submit" value="testRequestMethod" />
</form>
Same format for any environment: a sequence of “myParam=myValue” style expressions, with a request only mapped if each such parameter is found to have the given value. Expressions can be negated by using the “!=” operator, as in “myParam!=myValue”. “myParam” style expressions are also supported, with such parameters having to be present in the request (allowed to have any value). Finally, “!myParam” style expressions indicate that the specified parameter is not supposed to be present in the request.
代码
@RequestMapping(value = "/testParam", params = "userId=‘userName‘ ")
public String testParam() {
System.out.println("params userId is not null");
return "success";
}
<a href="springMVC/testParam.do?userId=userName ">testParam</a>
版权声明:本文为博主原创文章,未经博主允许不得转载。
SpringMVC -- @RequestMapping用法
标签:spring mvc
原文地址:http://blog.csdn.net/gaopeng0071/article/details/48002909