如何返回状态码202的HTTP响应?
我在Spring Boot文档中找不到任何参考。
答案 0 :(得分:4)
答案 1 :(得分:1)
您可以这样做(我正在使用kotlin):
return ResponseEntity.accepted().body(OrderResponse().order(order))
或简单的方法是:
return ResponseEntity.status(HttpStatus.CREATED).body(OrderResponse().order(order))
ResponseEntity.accepted返回202 ResponseEntity.created返回201 等等
答案 2 :(得分:-1)
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value=HttpStatus.NOT_FOUND, reason="No Article found with this Article Number.")
public class NoArticleFoundException extends RuntimeException{
private static final long serialVersionUID =3935230281455340039L;
}
代替编写NOT_FOUND,您可以编写ACCEPTED并在原因字段中提供一些文本。然后从另一个类或在需要时调用此方法。 (不需要扩展部分)