首页 > 解决方案 > 如何在 Maven 应用程序 java 中比较两个日期

问题描述

我创建了一个函数来获取一些与日期匹配的行。但是该功能没有相应地执行。我怀疑存在一些语法问题。请帮我找出问题。DaoImpl 函数如下:

public List<ReportSewing> getReport(Date reportDate) {
     return session.getCurrentSession()
             .createQuery("from ReportSewing where DATE(reportDate) = (reportDate)")
             .list();
}

标签: javaspringdatehqlwhere-clause

解决方案


好像你忘了传递查询参数。

public List<ReportSewing> getReport(Date reportDate) {
     return session.getCurrentSession()
         .createQuery("from ReportSewing where DATE(reportDate) = :reportDate")
         .setParameter("reportDate", reportDate)
         .list();
}

推荐阅读