"是否存在针对where条件"的数据库中的行数的捷径;如果我们有一个标准定义,它需要数据库中存在的行数是r2dbc中的任何函数给出的吗
你可以有这样的东西:
@Repository
public class MyCustomRepositoryImpl {
private final R2dbcEntityTemplate r2dbcEntityTemplate;
@Autowired
public MyCustomRepositoryImpl(DatabaseClient databaseClient) {
this.r2dbcEntityTemplate = new R2dbcEntityTemplate(databaseClient);
}
public Mono<Long> getCountOfAllRows() {
return r2dbcEntityTemplate.count(query(Criteria.empty()),MyEntity.class);
}
public Mono<Long> getCountOfRowsForACondition(String myVal) {
return r2dbcEntityTemplate.select(query(Criteria.where("mycolumn").is(myVal)),MyEntity.class);
}
}
注意这里query
是org.springframework.data.relational.core.query.Query
的静态方法