当 spring 启动时没有 Example
一切都很好,但是使用 Example
结果是空的
应用程序.java
@SpringBootApplication
public class SelkinApplication {
public static void main(String[] args) {
SpringApplication.run(SelkinApplication.class, args);
}
}
SvHistoryRep.java
public interface SvHistoryRep extends CrudRepository<SvHistory, Integer>, QueryByExampleExecutor<SvHistory> {
}
服务.java
@PostMapping(path = "getFilteredHistory")
public @ResponseBody void getFilteredHistory(@RequestBody SvHistory svHistory){
SvHistory history = new SvHistory();
history.setJobStatusId(1);
Example<SvHistory> example = Example.of(history);
svHistoryRep.findAll(example).forEach(System.out::println);
}
如果没有示例,它就可以工作。 svHistoryRep.findAll().forEach(System.out::println);
但是对于示例,我的结果为空
最佳答案
我的猜测:SvHistory
有一些使用默认值初始化的值。因此,不仅对 id 列进行相等性检查。
要检查这一点,请记录您的示例对象。如果存在任何非空值并且它们不等于搜索的对象,您将看到该错误。很可能原因是自动初始化的基本类型,如 int、boolean 等。
关于java - Spring QueryByExampleExecutor 空结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57720977/