简体   繁体   English

Spring QueryByExampleExecutor空结果

[英]Spring QueryByExampleExecutor empty result

When spring starts without Example everything is fine, but with Example the result is empty 如果没有Example春天开始了,一切都很好,但是有了Example ,结果为空

Application.java Application.java

@SpringBootApplication
public class SelkinApplication {

    public static void main(String[] args) {
        SpringApplication.run(SelkinApplication.class, args);
    }
}

SvHistoryRep.java SvHistoryRep.java

public interface SvHistoryRep extends CrudRepository<SvHistory, Integer>, QueryByExampleExecutor<SvHistory> {

}

Service.java 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);

    }

When without Example, it's work. 如果没有Example,那就可以了。 svHistoryRep.findAll().forEach(System.out::println);

But with Example, i have empty result 但是用Example,我有空结果

My Guess: SvHistory has some values, that are initialized with default values. 我的猜测: SvHistory具有一些用默认值初始化的值。 So there is an equality check not only on the id column. 因此,不仅在id列上进行相等检查。 To check this, log your example object. 要检查这一点,请记录您的示例对象。 If there are any non null values and they are not equal to the searched object, you'll see the bug. 如果存在任何非null值,并且它们不等于搜索到的对象,则将看到错误。 Very probably the reason is auto initialized primitive types like int, boolean etc. 原因很可能是自动初始化的原始类型,例如int,boolean等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM