【发布时间】:2018-12-07 03:10:12
【问题描述】:
我有一个返回一些HttpStatus 代码的api。并且根据代码,看门人将执行一些操作。以下只是 API 的框架。
@GetMapping("/globalretry")
public Mono<ResponseEntity> testGlobalRetryFilter(@RequestParam(name = "code") int code) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("code", code);
switch (code) {
case 200:
map.put("status", "SUCCESS");
break;
case 504:
map.put("status", "RETRY: GATEWAY_TIMEOUT");
break;
default:
map.put("status", "BAD_REQUEST");
break;
}
return Mono.just(new ResponseEntity(map, HttpStatus.valueOf(code)));
}
现在的问题是,如果我以这种方式返回响应码,那么 spring 无法识别来自Mono<ResponseEntity> 的状态码。任何人都可以帮助我如何以某种方式返回statuscode,以便spring可以识别响应的状态代码
【问题讨论】:
-
ResponseEntity 有一个构建器函数,您可以传递一个“int”,它会为您完成所有工作...... ResponseEntity.status(code).build() 这就是您要寻找的?
标签: spring-boot reactive-programming spring-webflux project-reactor