项目开发需要同时支持post和get请求,springboot项目中的设置如下:
@RequestMapping(value = "/GetPostRequest", method = {RequestMethod.GET,RequestMethod.POST})
拓展:
注解@RequestMapping 能够处理 HTTP 请求的方法, 比如 GET, PUT, POST, DELETE 以及 PATCH。
//其他请求方式的常用写法如下
@RequestMapping(value = "/rest", method = RequestMethod.GET)
String get() {
return "from get";
}
@RequestMapping(value = "/rest", method = RequestMethod.DELETE)
String delete() {
return "from delete";
}
@RequestMapping(value = "/rest", method = RequestMethod.POST)
String post() {
return "from post";
}
@RequestMapping(value = "/rest", method = RequestMethod.PUT)
String put() {
return "from put";
}