For the latest stable version, please use Spring Framework 6.2.4!spring-doc.cn

@ResponseBody

You can use the @ResponseBody annotation on a method to have the return serialized to the response body through an HttpMessageConverter. The following listing shows an example:spring-doc.cn

@GetMapping("/accounts/{id}")
@ResponseBody
public Account handle() {
	// ...
}
@GetMapping("/accounts/{id}")
@ResponseBody
fun handle(): Account {
	// ...
}

@ResponseBody is also supported at the class level, in which case it is inherited by all controller methods. This is the effect of @RestController, which is nothing more than a meta-annotation marked with @Controller and @ResponseBody.spring-doc.cn

You can use @ResponseBody with reactive types. See Asynchronous Requests and Reactive Types for more details.spring-doc.cn

You can use the Message Converters option of the MVC Config to configure or customize message conversion.spring-doc.cn

You can combine @ResponseBody methods with JSON serialization views. See Jackson JSON for details.spring-doc.cn