【发布时间】:2020-03-16 10:12:44
【问题描述】:
我正在使用带有响应式 mongodb 的 spring webflux (SpringBoot 2.1.9)。我的 build.gradle 的一部分在这里
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
对于我的 CRUD 操作,创建和删除作品。更新方法不会引发异常,但内容不会保存在数据库中。我做错了什么?
MyHandler.java
public Mono<ServerResponse> update(ServerRequest request) {
return request.bodyToMono(ListAndReview.class).
flatMap( update -> {
return listAndReviewRepo.findById(update.id).flatMap( previous -> {
previous.name = update.name;
previous.description = update.description;
return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).body(fromObject(listAndReviewRepo.save(previous)));
});
}
).
switchIfEmpty(ServerResponse.notFound().build());
}
【问题讨论】:
-
您能否尝试在您的
listAndReviewRepo中使用@Transactional注释您的findById方法 -
添加@Transactional 没有解决问题。
标签: mongodb spring-boot spring-webflux reactive