Spring QueryByExampleExecutor 空结果
Spring QueryByExampleExecutor empty result
当 spring 在没有 Example
的情况下启动时一切正常,但在 Example
的情况下结果为空
Application.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> {
}
Service.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);
}
如果没有 Example,它就可以工作。 svHistoryRep.findAll().forEach(System.out::println);
但是对于示例,我的结果为空
我的猜测:SvHistory
有一些值,用默认值初始化。因此,不仅 id
列有相等性检查。
要检查这一点,请记录您的示例对象。如果有任何非空值并且它们不等于搜索到的对象,您将看到错误。很可能原因是自动初始化的原始类型,如 int、boolean 等
当 spring 在没有 Example
的情况下启动时一切正常,但在 Example
的情况下结果为空
Application.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> {
}
Service.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);
}
如果没有 Example,它就可以工作。 svHistoryRep.findAll().forEach(System.out::println);
但是对于示例,我的结果为空
我的猜测:SvHistory
有一些值,用默认值初始化。因此,不仅 id
列有相等性检查。
要检查这一点,请记录您的示例对象。如果有任何非空值并且它们不等于搜索到的对象,您将看到错误。很可能原因是自动初始化的原始类型,如 int、boolean 等