I try to use JPA Repository to get data from my database. Here I want get all MyObject
between startdate
and enddate
.
Code
Repository
@GetMapping
List<Tache> getMyObjectsByStartdateAfterAndEnddateBefore(@RequestParam Date startdate,
@RequestParam Date enddate);
Controller
@GetMapping(params = {"startdate", "enddate"})
public ResponseEntity<?> findAllByStartdateAfterAndEnddateBefore(@RequestParam("startdate") String startdate,
@RequestParam("enddate") String enddate) throws ParseException {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date start = formatter.parse(startdate);
Date end = formatter.parse(enddate);
return new ResponseEntity<>(this.tacheResource.getMyObjectsByStartdateAfterAndEnddateBefore(start, end), HttpStatus.OK);
}
Entity
@Entity
public class MyObject {
@Id
private String id;
@ColumnDefault("CURDATE()")
private String startdate;
private String enddate;
...
}
GET request example
http://localhost:8082/myobject/?startdate=2019-02-19&enddate=2019-06-01
Error (into Repository)
Expected parameter types : String, String
However, I don't understand why because I defined the method with Date
type as parameter. Is it because dates are stored as String
into my entity?