I use spring boot 2
Controller part
@PostMapping("template/new/samplings")
@ResponseBody
public SamplingsDto save(@ModelAttribute SamplingsDto samplings) {
return samplingsService.save(samplings);
}
I try to do save a form
$("#samplingsForm").submit(function (e){
e.preventDefault();
var receptionDate = $("#samplingsReceptionDatePicker").data('daterangepicker').startDate.format('YYYY-MM-DD');
var buildDate = $("#samplingsBuildDatePicker").data('daterangepicker').startDate.format('YYYY-MM-DD');
var form = transForm.serialize('#samplingsForm');
form.receptionDate=receptionDate;
form.buildDate=buildDate;
form = JSON.stringify(form);
$.ajax({
type:"post",
url: "/template/new/samplings",
data: form,
contentType: "application/json",
dataType : "json",
success: function(data){
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
}
});
});
With chrome request payload is
"{" "samplingsId":"", "buildDate":"2018-06-20", "receptionDate":"2018-06-20", "productTypesId":"1", "productsId":"15", "}"
On the server model attribute field are null
Edit
public class SamplingsDto {
private Integer samplingsId;
private Integer productTypesId;
private Integer productsId;
private LocalDate receptionDate;
private LocalDate buildDate;
//get set
}