httppost Frombody
时间: 2023-08-01 19:15:12 浏览: 52
HttpPost is a class in Java that represents an HTTP POST request. It is often used to send data to a server. The @RequestBody annotation is used with the method parameter to indicate that the parameter should be bound to the body of the HTTP request.
For example:
```
@PostMapping("/example")
public ResponseEntity<String> exampleMethod(@RequestBody String requestBody) {
// do something with the requestBody
return ResponseEntity.ok().body("Success");
}
```
In this example, the @RequestBody annotation is used to bind the parameter `requestBody` to the body of the HTTP request. When a POST request is made to the `/example` endpoint, the data in the body of the request will be passed to the `exampleMethod` as a string.
The `ResponseEntity` class is used to build the HTTP response that will be returned to the client. In this case, the response will have a status code of `200 OK` and a body of "Success".