1
I have the following problem here: I have a request that I make by ajax, and send a date for it, the java receives and saves in the bank, but the date that arrives in java is different from the one I sent. Follow the code:
Ajax request:
var episodio = {
titulo : $('#inputTitulo').val(),
descricao : $('#textSinopse').val(),
sneakPeak : $('#inputTrailer').val(),
dataEstreia : $('#inputDataEstreia').val(),
numero : $('#inputNumero').val(),
duracao : $('#inputDuracao').val()
};
$.ajax({
url: '/seriesmais/ajax/episodio/',
dataType: 'json',
method: 'POST',
data: episodio,
success: function(episodioRecebida) {
alert('inseriu');
}
});
Controller method:
@RequestMapping(value = "/", method = RequestMethod.POST)
public ResponseEntity<Object> salvar(Episodio episodio) {
System.out.println(episodio);
try {
if (episodio.getId() == null){
System.out.println("DATA: " + episodio.getDataEstreia());
daoEpisodio.inserir(episodio);
} else {
daoEpisodio.alterar(episodio);
}
return ResponseEntity.status(HttpStatus.OK).body(episodio);
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
Data in the model (I was using without the Datetimeformat annotation, and it didn’t work either, I put it to see if it worked, it didn’t work):
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(pattern = "dd/MM/yyyy")
private Date dataEstreia;
I’m taking the date of the bootstrap datepicker, but the date coming out of it is correct:
$('.datepicker').datepicker({
weekStart:1,
format: 'dd/mm/yyyy'
});
But the date that arrives in java is another:
Can anyone help me? Thank you!