Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 搜索两个日期之间的顺序Hibernate,Spring Boot_Spring Boot_Spring Data Jpa_Crud - Fatal编程技术网

Spring boot 搜索两个日期之间的顺序Hibernate,Spring Boot

Spring boot 搜索两个日期之间的顺序Hibernate,Spring Boot,spring-boot,spring-data-jpa,crud,Spring Boot,Spring Data Jpa,Crud,我有一个实体作为订单,其中有一列作为日期。现在我想做一个自定义搜索,返回两个日期之间的所有订单。我该怎么做 这是订单实体 package com.example.API.Entities; import org.hibernate.annotations.CreationTimestamp; import javax.persistence.*; import java.math.BigInteger; import java.util.Date; import java.util

我有一个实体作为订单,其中有一列作为日期。现在我想做一个自定义搜索,返回两个日期之间的所有订单。我该怎么做

这是订单实体

    package com.example.API.Entities;


import org.hibernate.annotations.CreationTimestamp;

import javax.persistence.*;
import java.math.BigInteger;
import java.util.Date;
import java.util.List;

@Entity
public class Orders {
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private BigInteger id;

    @CreationTimestamp
    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = false)
     private Date date;
    @PrePersist
    protected void onCreate() {
        date = new Date();
    }

    @PostPersist
    protected void onUpdate() {
        date = new Date();
    }


    @ManyToOne
    @JoinColumn(name = "user_id")
    private User user;

    public Orders(){}
    public Orders(BigInteger id, Date date,BigInteger userId) {
        super();
        this.id = id;
        this.date = date;
        this.user=new User(userId," ",0000000000L," ");
    }

    public BigInteger getId() {
        return id;
    }

    public void setId(BigInteger id) {
        this.id = id;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }
}
这是存储库

    public interface OrdersRepository extends CrudRepository<Orders,BigInteger> {
    public List<Orders>findByUserId(BigInteger userId);
}
public interface ordersepository扩展了crudepository{
公共ListfindByUserId(BigInteger用户ID);
}
我对如何编写findAllByDate方法感到困惑

我也想用API来实现这一点。 任何事都会有很大的帮助
那么,我是否也应该有一个请求主体,或者是否有其他方法在您的存储库中创建这样的方法

 public List<Orders> findByDateBetween(Date from, Date to)
公共列表findByDateBetween(日期从,日期到)

spring数据将处理其余部分。这将获取日期介于from和to之间的订单

以及如何从用户处获取“from”和“to”?这取决于您的需求和体系结构。除非我知道全部细节,否则不能提出建议。您可以根据需要接受用户提供的日期。但是这个方法会给你带来你想要的结果,给你日期。你需要什么细节?你如何保存订单。你有休息电话吗?如果是,则从用户处获取日期作为rest请求。是否向上投票/接受答案这里的中间表示等于第一个,低于结尾,或者如果我需要包含结尾,我可以使用哪个函数?