下面指定参数foo,只要含有该参数就行不管是否还有其他参数
@RequestMapping(value="param", method=RequestMethod.GET)
public @ResponseBody String withParam(@RequestParam String foo) {
return "Obtained 'foo' query parameter value '" + foo + "'";
}
url=/data/group?param1=foo¶m2=bar¶m3=baz
@RequestMapping(value="group", method=RequestMethod.GET)
public @ResponseBody String withParamGroup(JavaBean bean) {
return "Obtained parameter group " + bean;
}
JavaBean为带有param1,param2,param3属性的bean
url=../path/+任意变量
与@RequestMapping(value=“/mapping/path/*“相似
@RequestMapping(value="path/{var}", method=RequestMethod.GET)
public @ResponseBody String withPathVariable(@PathVariable String var) {
return "Obtained 'var' path variable value '" + var + "'";
}
@RequestMapping(value="{path}/simple", method=RequestMethod.GET)
public @ResponseBody String withMatrixVariable(@PathVariable String path, @MatrixVariable String foo) {
return "Obtained matrix variable 'foo=" + foo + "' from path segment '" + path + "'";
}
@RequestMapping(value="{path1}/{path2}", method=RequestMethod.GET)
public @ResponseBody String withMatrixVariablesMultiple (
@PathVariable String path1, @MatrixVariable(value="foo", pathVar="path1") String foo1,
@PathVariable String path2, @MatrixVariable(value="foo", pathVar="path2") String foo2) {
return "Obtained matrix variable foo=" + foo1 + " from path segment '" + path1
+ "' and variable 'foo=" + foo2 + " from path segment '" + path2 + "'";
}
@RequestHeader
获取header
@RequestMapping(value="header", method=RequestMethod.GET)
public @ResponseBody String withHeader(@RequestHeader String Accept) {
return "Obtained 'Accept' header '" + Accept + "'";
}
@CookieValue
@RequestMapping(value="cookie", method=RequestMethod.GET)
public @ResponseBody String withCookie(@CookieValue String openid_provider) {
return "Obtained 'openid_provider' cookie '" + openid_provider + "'";
}
@RequestBody
@RequestMapping(value="body", method=RequestMethod.POST)
public @ResponseBody String withBody(@RequestBody String body) {
return "Posted request body '" + body + "'";
}
$.ajax({ type: "POST", url: form.attr("action"), data: "foo", contentType: "text/plain", dataType: "text", success: function(text) { MvcUtil.showSuccessResponse(text, button); }, error: function(xhr) { MvcUtil.showErrorResponse(xhr.responseText, button); }});
body=foo
request header and body--> HttpEntity
@RequestMapping(value="entity", method=RequestMethod.POST)
public @ResponseBody String withEntity(HttpEntity<String> entity) {
return "Posted request body '" + entity.getBody() + "'; headers = " + entity.getHeaders();
}
```java
public class HttpEntity<T> {
public static final HttpEntity EMPTY = new HttpEntity();
private final HttpHeaders headers;
private final T body;
...