【问题标题】:get all rows from the start date to end date inclusive with QueryDSL(Mongodb)使用QueryDSL(Mongodb)获取从开始日期到结束日期的所有行
【发布时间】:2020-11-05 10:28:59
【问题描述】:

我有这个 queryDSL 查询:

    QReport report = QReport.report;
    BooleanBuilder builder = new BooleanBuilder();

    if (startDate != null) {
        builder.and(report.modificationDate.after(startDate));
    }

    if (endDate != null) {
        builder.and(report.modificationDate.before(endDate));
    }

但如果我想查找从 09/04/201809/04/2018 的行,它就行不通了。 或者从 09/04/201809/05/2018 - 仅找到 09/04/2018 行。

我可以将 23.59.59 时间添加到 endDate 但也许在查询 DSL 中有一些选项?

例如 - 获取从开始日期到结束日期的所有行

【问题讨论】:

    标签: mongodb date spring-data-mongodb querydsl predicate


    【解决方案1】:

    TemporalExpressionLiteralExpression,它是 QueryDSl 中的 ComparableExpressionTemporalExpression#before 只是ComparableExpression#lt 的替代品(小于)。 ComparableExpression 也有 loe(...)(用于小于或等于)。

    因此您可以将代码更改为report.modificationDate.loe(endDate)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-14
      • 2019-04-23
      • 2020-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多