作者:袁怡松_779 | 来源:互联网 | 2022-10-14 16:57
这是我删除项目的控制器:
public Mono delete(
@PathVariable(value = "id") String id) {
return itemService.delete(id)
.map(aVoid -> ResponseEntity.ok());
}
itemService.delete(id)
退货 Mono
但是,当我成功删除一个项目时,它没有给我响应实体对象。它仅返回空白json。
我似乎未执行地图,因为delete方法返回 Mono
如何正确做到这一点?
1> Brian Clozel..:
A reactive streams publisher can send 3 types of signals: values, complete, error.
A Mono
publisher is way to signal when an operation is completed - you're not interested in any value being published, you just want to know when the work is done. Indeed, you can't emit a value of a Void
type, it doesn't exist.
The map
operator you're using transforms emitted values into something else.
So in this case, the map operator is never called since no value is emitted. You can change your code snippet with something like:
public Mono delete(
@PathVariable(value = "id") String id) {
return itemService.delete(id)
.then(Mono.just(ResponseEntity.ok()));
}