Problems with between LocalDate Predicate

大城市里の小女人 提交于 2019-12-12 17:15:46

问题


This is my table

The selected column is the one that I'm using in Predicate

My first approach was

  public void betweenPredicate(String attrib, LocalDate value, LocalDate value2) {
        Predicate predicate = builder.between(entity.<LocalDate> get(attrib), builder.literal(value), builder.literal(value2));                
        predList.add(predicate);
    }

But in that way some date are missing, so I change to this

 public void betweenPredicate(String attrib, LocalDate value, LocalDate value2) {
        Predicate predicate = builder.and(builder.<LocalDate>greaterThan(entity.get(attrib), value),
                builder.<LocalDate>lessThan(entity.get(attrib), value2));
        predList.add(predicate);
    }

In that way works perfeclty, so my question is What is the main different betweent this two way, Am I done something wrong?

EDIT

This is my screen I'm using netbeans 8.2 with DatePicker from swingx 1.6

DatePicker send me Date, but my class receive LocalDate so a have this Convert Method

public static LocalDate dateToLocalDate(Date data) {
        if (data != null) {
            return data.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
        } else {
            return null;
        }
    }

and I added two println at betweenPredicate to see how the values are getting there and this is the output

V: 2018-02-01
V2: 2018-02-16

来源:https://stackoverflow.com/questions/48585691/problems-with-between-localdate-predicate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!