“对于根据where 条件数据库中没有.of 行,有什么简写吗?” 如果我们有一个标准定义,它需要数据库中存在的行数。 是 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
的静态方法
关于spring - 相对于 r2bc 中的 where 子句,我们是否有一个简写来计算 db 中存在的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62775211/