There are a few issues you can check that might cause a no return on your date request. I have added comments in your code where you can check. I have also added the 'System.out.println' to debug all returned parameters in your controller, check each item returned for it's value and confirm that it is what you expected. You should really start using debug statements in your code, it will make life so much easier.
In your controller -
@GetMapping("/handovers/search")
public String searchHandovers(@RequestParam("fromDate") String fromDate,
@RequestParam("toDate") String toDate,
Model model) {
System.out.println("Received fromDate: " + fromDate);
System.out.println("Received toDate: " + toDate);
Date sqlFromDate = Date.valueOf(fromDate);
Date sqlToDate = Date.valueOf(toDate);
System.out.println("Converted fromDate: " + sqlFromDate);
System.out.println("Converted toDate: " + sqlToDate);
List<Handover> handovers = handoverService.getHandoversInRange(sqlFromDate, sqlToDate);
System.out.println("Retrieved handovers: " + handovers);
model.addAttribute("handover", handovers);
return "handovers/handover :: handoverTableBody";
}
In your HandoverRepository -
public interface HandoverRepository extends JpaRepository<Handover, Long> {
@Query("SELECT handover FROM Handover handover WHERE handover.date >= :fromDate AND handover.date <= :toDate")
List<Handover> getHandoversInRange(@Param("fromDate") Date fromDate, @Param("toDate") Date toDate);
}
In your HandoverServiceImpl -
@Override
public List<Handover> getHandoversInRange(Date fromDate, Date toDate) {
return handoverRepository.getHandoversInRange(fromDate, toDate);
}