Can Spring Data REST's QueryDSL integration be used to perform more complex queries?

后端 未结 3 1195
一向
一向 2020-11-30 22:49

I\'m currently building a REST API in which I want clients to easily filter on most properties of a specific entity. Using QueryDSL in combination with Spring Data REST (an

3条回答
  •  感情败类
    2020-11-30 23:30

    This is what I used for a generic binding for all date fields, always expecting 2 values, from and to.

    bindings.bind(Date.class).all((final DateTimePath path, final Collection values) -> {
        final List dates = new ArrayList<>(values);
        Collections.sort(dates);
        if (dates.size() == 2) {
            return path.between(dates.get(0), dates.get(1));
        }
        throw new IllegalArgumentException("2 date params(from & to) expected for:" + path + " found:" + values);
    });
    

    This is for datetime fields. For a date field, when getting a single parameter, path.eq() makes sense I guess.

提交回复
热议问题