Spring中ResponseEntity和HttpEntity有什么区别?

Tim*_*lbe 1 java spring

我想知道两者之间的区别以及何时在SpringMVC Controller中使用它们。

提姆

Aka*_*Roy 5

HttpEntity可用于创建RequestEntity和ResponseEntity。

其中,ResponseEntity是从HttpEntity继承的子类,具有发送发送ResponseObject的更为详尽的方法,并且仅限于发送Response。一些主要区别如下:

  1. 从HttpEntity继承的ResponseEntity在发送ResponseEntity对象时具有附加的HttpStatus代码。

  2. 它还具有将实体添加到响应对象的ResponseEntity.BodyBuilder和将标题添加到响应对象的ResponseEntity.HeadersBuilder。