2 回答

TA貢獻1784條經驗 獲得超7個贊
您正在構建一個Example,然后通過不使用它而丟棄它。您正在調用userRepository.count();它基本上計算所有記錄。您應該使用count帶有Example.
這個方法在QueryByExampleExecutor你的界面上,也UserRepository應該擴展。那么你可以簡單地做。
Example<User> example = Example.of(User.builder().firstName("Mike").build());
long count = userRepository.count(example);
System.out.println(count);
你應該得到你期望的結果。

TA貢獻2080條經驗 獲得超4個贊
我遇到了類似的問題。解決方案是將 spring-data-redis 和 spring-data-common 包升級到相同版本。如果您使用的是 maven:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
添加回答
舉報