请提供更多代码,如何声明控制器以及它可以采用哪些参数。还显示一个示例请求。这是一个简单控制器的示例:
一个模型
public class CustomRequestBody {
private String fieldA;
private String fieldB;
public String getFieldA() {
return fieldA;
}
public void setFieldA(final String fieldA) {
this.fieldA = fieldA;
}
public String getFieldB() {
return fieldB;
}
public void setFieldB(final String fieldB) {
this.fieldB = fieldB;
}
}
控制器:
@Controller
public class MyController {
@RequestMapping(value = "/some-path", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.ACCEPTED)
public ResponseEntity handleSomePath(@RequestBody final CustomRequestBody body, final HttpServletRequest request) {
// Do the job.
}
请求将是:
HTTP POST http://some.server.com/some-path
{
"fieldA":"first value",
"fieldB":"second value"
}
在此处阅读更多 Spring 文档