在spring boot@repositoryrestresource的情况下测试between关键字的rest api

8iwquhpp  于 2021-07-24  发布在  Java
关注(0)|答案(0)|浏览(283)

我想取两个日期之间的记录。我对pojo类和存储库接口做了如下介绍。
通信.java

package com.example.TaskManagerApp.POJO;

import java.time.LocalDate;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Company 
{
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    int id;
    String name;
    String owner;
    String contact;
    LocalDate expDate;
    int maxTasks;
    int maxUsers;

    public Company() {
    }

    public Company(String name, String owner, String contact, LocalDate expDate, int maxTasks, int maxUsers) {
        this.name = name;
        this.owner = owner;
        this.contact = contact;
        this.expDate = expDate;
        this.maxTasks = maxTasks;
        this.maxUsers = maxUsers;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getOwner() {
        return owner;
    }

    public void setOwner(String owner) {
        this.owner = owner;
    }

    public String getContact() {
        return contact;
    }

    public void setContact(String contact) {
        this.contact = contact;
    }

    public LocalDate getExpDate() {
        return expDate;
    }

    public void setExpDate(LocalDate expDate) {
        this.expDate = expDate;
    }

    public int getMaxTasks() {
        return maxTasks;
    }

    public void setMaxTasks(int maxTasks) {
        this.maxTasks = maxTasks;
    }

    public int getMaxUsers() {
        return maxUsers;
    }

    public void setMaxUsers(int maxUsers) {
        this.maxUsers = maxUsers;
    }
}

公司地址.java

package com.example.TaskManagerApp.repository;

import com.example.TaskManagerApp.POJO.Company;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

@RepositoryRestResource
public interface CompanyRepository extends JpaRepository<Company, Integer>{

}

现在我想测试api,
为了得到所有的记录,我使用如下网址,

GET : http://localhost:8080/companies

为了获取expdate为2021年1月28日的所有记录,我使用如下url

GET : http://localhost:8080/companies?findByExpDate="2021-01-28"

这里findbycolumnname是spring boot自动提供的方法,如官方文档中所述:https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-方法.查询-创建
类似地,也有findbycolumnnamebetween方法
找出两次约会之间的日期的方法是什么?如何打发两次约会?

> GET :
> http://localhost:8080/companies?findByExpDateBetween="2021-01-01"......

如何为between关键字指定第二个日期?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题