是否有一个不平等条件的检查程序



我正在使用春季数据JPA,我想在querybyexample(qbe(中知道我可以获得所有记录(其中colum value而不是等于'xxx'(

我已经看过审查员,但找不到类似不等式的东西

        Employee filterBy = new Employee();
        filterBy.setLastName("ar"); 
        //Filter - ignore case search and contains 
        ExampleMatcher matcher = ExampleMatcher.matching()     
                  .withStringMatcher(StringMatcher.CONTAINING)   // Match string containing pattern   
                  .withIgnoreCase();                 // ignore case sensitivity 
        example = Example.of(filterBy, matcher);

上面的代码获取所有记录是lastname ar ar的所有记录,但我正在寻找姓氏不应该是" ar"。还有其他检查程序吗?

BizExceptionConfig condition = configRequestPair.getCondition();
ExampleMatcher exampleMatcher = ExampleMatcher.matching()
        .withMatcher("appCode", startsWith())
        .withMatcher("name", startsWith())
        .withMatcher("code", startsWith());
if(Objects.isNull(condition.getLifecycle())){
    condition.setLifecycle(LifeCycle.DELETE.getCode());
    HashMap<String, Integer> params = new HashMap<>();
    params.put("$ne", LifeCycle.DELETE.getCode());
    exampleMatcher = exampleMatcher.withTransformer("lifecycle", (obj) -> Optional.of(params));
}
Example<BizExceptionConfig> example = Example.of(condition, exampleMatcher);
Page<BizExceptionConfig> pageRecord = bizExcConfigRepository.findAll(example, PageUtil.toPageRequest(configRequestPair.getPage()));`enter code here`

可以通过" TransFormer"解决此问题。JPA相当有限,因此,我建议使用Mongotmpl。希望它可以帮助您

可以通过使用 REGEX作为stringMatcher来解决您的问题,并且该解决方案看起来如下:

Employee filterBy = new Employee();
filterBy.setLastName("ar");
filterBy.setLastName(String.format("^(?!.*$1$).*$", Pattern.quote(filterBy.getLastName())));
//filterBy.setLastName(String.format(".*(?<!$1)$", Pattern.quote(filterBy.getLastName())));  // this would be another alternative
ExampleMatcher matcher = ExampleMatcher.matching()
    .withStringMatcher(StringMatcher.REGEX)   // Match string containing pattern   
                  .withIgnoreCase();                 // ignore case sensitivity
Example example = Example.of(filterBy, matcher);

不幸的是,即使开发人员最初会认为正则表达式得到了支持(由于存在上述枚举常数(,Spring实际上实际上不支持它们 - 并且根据对相关JIRA问题的讨论,它从未赢得过't:https://jira.spring.io/browse/datajpa-944

最新更新