我无法将文档保存到沙发库。
这是我的代码库。我在码头工人中运行沙发基地。
我使用查询在数据库中手动添加了一个文档。
repo.findAll(( 工作正常,但 repo.save(person( 不起作用。
有人可以帮我吗?
人.java
@Document
@Getter
@Setter
@AllArgsConstructor
public class Person {
@Id
private String id;
@Field
@NotNull
private String firstName;
@Field
@NotNull
private String lastName;
@Field
@NotNull
private String created;
@Field
private String updated;
}
人员存储库.java
public interface PersonRepository extends ReactiveCrudRepository<Person,String> {
Flux<Person> findByFirstName(String firstName);
Flux<Person> findByLastName(String lastName);
}
个人服务.java
public interface PersonService {
@View(designDocument = "_design/person",viewName = "all")
Flux<Person> findAll();
Flux<Person> findByFirstName(String firstName);
Flux<Person> findByLastName(String lastName);
void create(Person person);
}
PersonRepositoryService.java
@Service
@Slf4j
public class PersonRepositoryService implements PersonService{
@Autowired
private PersonRepository repo;
@Override
public Flux<Person> findAll() {
return repo.findAll();
}
public Flux<Person> findByFirstName(String firstName){
return repo.findByFirstName(firstName);
}
@Override
public Flux<Person> findByLastName(String lastName) {
return repo.findByLastName(lastName);
}
public void create(Person person){
person.setCreated(LocalDateTime.now().toString());
repo.save(person);
}
}
ICustomerAccountAPI.java
@RequestMapping("/customerAccountManagement/v1/")
public interface ICustomerAccountAPI {
@PostMapping(value = "/createProfile", consumes = APPLICATION_JSON)
@ResponseStatus(HttpStatus.OK)
Mono<Person> createCustomerProfile(@RequestBody @Valid Mono<Person> person);
}
客户账户API.java
@RestController
@Slf4j
public class CustomerAccountAPI implements ICustomerAccountAPI {
@Autowired PersonRepositoryService personRepositoryService;
@Override
public Mono<Person> createCustomerProfile(@RequestBody Mono<Person> person) {
return person.map( person1 ->{
personRepositoryService.create(person1);
return person1;
});
}
这些是我在POM中添加的与此相关的依赖项。
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-couchbase</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>com.couchbase.client</groupId>
<artifactId>java-client</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>io.reactivex</groupId>
<artifactId>rxjava-reactive-streams</artifactId>
<version>0.3.0</version>
</dependency>
请在这里看我的回答:使用 Spring 数据更新对象 MongoDB 和 Kotlin 不起作用
这是同样的问题:什么都不会发生,因为没有人订阅这个发布者(Mono(。返回单声道(repo.save(person)
(作为Spring控制器的响应将解决此问题。Spring将订阅该Mono,将调用repo.save(person(方法,然后Spring将发送HTTP响应。