在JPA中选择日期范围

时间:2018-10-03 10:07:20

标签: java hibernate jaxb single-page-application

我希望发送带有Date的XML以返回XML响应。我尝试过:

XML请求:

<?xml version="1.0" encoding="UTF-8"?>
<reconcile>
  <start_date>2018-04-08</start_date>
  <end_date>2018-11-08</end_date>
  <page>1</page>
</reconcile>

JAXB:

    @XmlElement(name = "start_date")
    public Date start_date;
    @XmlElement(name = "end_date")
    public Date end_date;
    @XmlElement(name = "page")
    public String page;

导入java.util.Date;

        Date start_date, Date end_date,
        String hql = "select e from " + PaymentTransactions.class.getName() + " e where e.created_at >= ? and e.created_at <= ? and e.merchant_id = ? and e.terminal_id = ?";
        Query query = entityManager.createQuery(hql).setParameter(0, start_date).setParameter(1, end_date).setParameter(2, merchant.getId()).setParameter(3, terminal.getId());
        List<PaymentTransactions> paymentTransactions = (List<PaymentTransactions>) query.getResultList();
        return paymentTransactions;

对于表列类型,我使用的是MariaDB DATE类型。

但是当我发送请求时,什么都没有发生。 在发送SQL查询之前,可能需要转换数据吗?你能提出一些解决方案吗?

0 个答案:

没有答案