ResponseEntity 未按应有的方式显示

问题描述 投票:0回答:1

我试图从响应实体获取正确的 statusCode,但是当我使用 insomnia 发出请求时,

ResponseEntity
显示为对象,但实际的 statusCode 始终为
200
,即使 y 手动将其设置为
400

这是我的代码:

@GET
@Path("/tipoArchivos/{id}")
public ResponseEntity<?> getTipoArchivos(@PathParam("id")String idProceso) throws Exception{
    Optional<List<TipoArchivoDTO>> respuesta = Optional.ofNullable(tramiteInt.getAttachmentTypes(idProceso));
    if (!respuesta.isPresent()) {
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.set("#status#", "400");
        ResponseEntity<String> respuesta1 = new ResponseEntity<String>("El codigo del proceso solo debe contener tres caracteres en mayuscula", responseHeaders, HttpStatus.BAD_REQUEST);
        return respuesta1;
    }
    return new ResponseEntity<List<TipoArchivoDTO>>(respuesta.get(), HttpStatus.OK);
}

这就是我得到的: ActualResponse 我在这里做错了什么?感谢您的宝贵时间

java httpresponse
1个回答
0
投票

我不认为 ResponseEntity 可以与 Dropwizard 一起使用(我假设这就是您基于注释所使用的),因为它来自 Spring -

org.springframework.http.ResponseEntity
。 对于 Dropwizard,您应该使用:
javax.ws.rs.core.Response

© www.soinside.com 2019 - 2024. All rights reserved.