I have an application that already exists and I have to add a column in the database with JPA to save a "Timestamp" (complete date with time) and then make an endpoint to receive this "Timestamp" but I'm new to Java and programming and I'm not sure how to do it. I tried to do like this:
Service:
@Column(name="timeStamp", columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
@Temporal(TemporalType.TIMESTAMP)
public Date getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(Date timeStamp) {
this.timeStamp = timeStamp;
}
Controller:
@PostMapping(
value = "/{date}",
produces = MediaType.APPLICATION_JSON_VALUE
)
public ResponseEntity<?> testDate(@RequestParam Timestamp date){
return ResponseEntity.ok().body(VisitantService.getTimeStamp());
}
But it keeps giving error.