I have the following problem here: I have a request that I make through ajax, and I send a date for it, java receives and saves it in the database, but the date that arrives in java is different from the one I sent. Follow the codes: Home 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');
}
});
Method not controller:
@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);
}
}
Date in the model (I was using it without the DateTimeFormat annotation, and it did not work either, I put it to see if it worked, it did not work):
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(pattern = "dd/MM/yyyy")
private Date dataEstreia;
I'm getting the bootstrap datepicker date, but the date it exits is correct:
$('.datepicker').datepicker({weekStart:1,format:'dd/mm/yyyy'});
Butthedatethatarrivesinjavaisanother:
Can anyone help me? Thanks!