Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
212 views
in Technique[技术] by (71.8m points)

Test REST Api for BETWEEN keyword in case of Spring Boot @RepositoryRestResource

I want to fetch records bewtween two dates. I've POJO class and Repository interface as follow.

Comapny.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;
    }
}

CompanyRepository.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>{
    
}

Now I want to test api,

For getting all the records, I use url as follow,

GET : http://localhost:8080/companies

For getting all records having expDate as 28-January-2021, I use url as follow

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

here findByColumnName is method which is automatically provided by Spring Boot as stated in official document : https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.query-creation

Similarly there is method findByColumnNameBetween

What is way to find out expDate between two dates? How to pass two dates?

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

How to specify 2nd date for between keyword?

question from:https://stackoverflow.com/questions/65942940/test-rest-api-for-between-keyword-in-case-of-spring-boot-repositoryrestresource

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...