RequestMapping

1 常规

@RequestMapping(value = "/", method = RequestMethod.GET)
public String index(){
  return "hello world";
}

2 带参数

@RequestMapping(value="/{id}", method=RequestMethod.GET)
public String index(@PathVariable String id){
  return "This is "+ id;
}

3 方法仅处理request Content-Type为“application/json”类型的请求。

@RequestMapping(value = "/pets", method = RequestMethod.POST, consumes="application/json")

4 方法仅处理request请求中Accept头中包含了"application/json"的请求,同时暗示了返回的内容类型为application/json;

@RequestMapping(value = "/pets/{petId}", method = RequestMethod.GET, produces="application/json")

你可能感兴趣的:(RequestMapping)