对于r2bc中的where子句,我们是不是用简写法来计算db中存在的行数



"是否存在针对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);
}
}

注意这里queryorg.springframework.data.relational.core.query.Query的静态方法

最新更新