我想在创建资源及其位置后发送 201 HTTP 响应。
HTTP/1.1 201 Created
Location: http://www.example.org/myresource/12546
你如何定义你的@ApiMethod
?
我想在创建资源及其位置后发送 201 HTTP 响应。
HTTP/1.1 201 Created
Location: http://www.example.org/myresource/12546
你如何定义你的@ApiMethod
?
如文档中所述:
如果 API 方法成功返回,端点通常会假定 HTTP 200。如果 API 方法响应类型为 void 或 API 方法返回值为 null ,则改为设置 HTTP 204。HTTP 2xx 代码不应在自定义异常类中使用。
话虽如此,如果您仍然需要返回 201 代码,您可以破解服务异常来提供它。
public class EverythingOKException extends ServiceException {
public EverythingOKException(String message) {
super(201, message);
}
}