Spring Boot Search Data Between Two Dates

Spring Boot search data between two dates

It's best that you receive the parameters as String and then convert the String to LocalDate in your controller.

@RequestMapping(value="/movementsByDate", method = RequestMethod.GET)
public Page<Mouvements> movementsByDate(
@RequestParam(name= "dateBefore", defaultValue="")String dateBeforeString,
@RequestParam(name= "dateAfter", defaultValue="")String dateAfterString,
@RequestParam(name= "page", defaultValue="0")int page,
@RequestParam(name= "size", defaultValue="5")int size){

LocalDate dateBefore = LocalDate.parse(dateBeforeString, DateTimeFormatter.ofPattern("dd/MM/yyyy"));
LocalDate dateAfter = LocalDate.parse(dateAfterString, DateTimeFormatter.ofPattern("dd/MM/yyyy"));

return mouvementsRepository.getMouvementsByDate(dateBefore, dateAfter, new PageRequest(page, size));
}

Searching an order between two dates Hibernate, Spring Boot

Create a method like this in your repository

 public List<Orders> findByDateBetween(Date from, Date to)

spring-data will take care of the rest. This will fetch the orders which has date between from and to



Related Topics



Leave a reply



Submit