Pessoal, Eu estou tentando fazer uma busca por usuario e datas(Between), porem aparece um erro de conversão de string e eu não estou sabendo como e onde alterar, tentei, mas em varias tentativas acontece o erro abaixo;
@Column(name = "bet_date", nullable = true)
private Date betDate;
Repository
Page<BettingSlip> findByUserValidatorUsernameAndBetDateBetween(String username,Date startDate,Date endDate,Pageable pages);
Controller
@GetMapping(value = "searchBettingSlipByUsernameValidatorAndDate/{usernameValidator}/{startDate}/{endDate}/{page}/{count}") public ResponseEntity<Response<?>> findByUserValidatorUsername( @PathVariable("usernameValidator") String usernameValidator, @PathVariable("startDate") Date startDate, @PathVariable("endDate") Date endDate, @PathVariable int page, @PathVariable int count) throws ParseException { Response<Page<BettingSlip>> response = new Response<Page<BettingSlip>>(); Page<BettingSlip> bettingSlipRecords = bettingSlipService.findByUserValidatorUsernameAndBetDateBetween( usernameValidator, startDate, endDate,page, count); response.setData(bettingSlipRecords); return ResponseEntity.ok(response); }
No meu banco o resultado inserido fica
"2019-05-16 20:10:08"
No postman
{
“timestamp”: “2019-05-16T13:07:08.962+0000”,
“status”: 400,
“error”: “Bad Request”,
“message”: “Failed to convert value of type ‘java.lang.String’ to required type ‘java.util.Date’; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@org.springframework.web.bind.annotation.PathVariable java.util.Date] for value ‘2019-05-13 20:10:08’; nested exception is java.lang.IllegalArgumentException”,
“path”: “/api/auth/searchBettingSlipByUsernameValidatorAndDate/ewegkz/2019-05-13%2020:10:08/2019-05-16%2020:10:08/0/300”
}
Link utilizado foi;
`
http://localhost:8080/api/auth/searchBettingSlipByUsernameValidatorAndDate/ewegkz/2019-05-13 20:10:08/2019-05-16 20:10:08/0/300
`
Sei que teria que converter, mas não sei como usei o dateFormat no controller mas dava erro na conversão, passei o pathVariable para string e tbm deu erro, imagino que é na forma como estou fazendo.