将表单发布到spring控制器,发布localdate

时间:2018-05-19 18:12:56

标签: javascript jquery spring

我使用带有弹簧靴2的百里香叶3

我尝试保存表单

我的控制器

@PostMapping("template/new/samplings")
@ResponseBody
public SamplingsDto save(@RequestBody SamplingsDto samplings) {
    return samplingsService.save(samplings);
}

我做提交,我需要修改一些值(日期),以确保将其发送到标准格式。

我的js

var receptionDate =  $("#samplingsReceptionDatePicker").data('daterangepicker').startDate.format('YYYY-MM-DD');
var buildDate =  $("#samplingsBuildDatePicker").data('daterangepicker').startDate.format('YYYY-MM-DD');

$("#samplingsForm").submit(function (e){
     var data = $("#samplingsForm").serializeArray();
     data.find(item => item.name === 'receptionDate').value = receptionDate;
     data.find(item => item.name === 'buildDate').value = buildDate;

     $.ajax({
         type:"post",
         url: "/template/new/samplings",
         data: data,
         contentType: "application/json",
         success: function(data){ 
         },
         error: function (XMLHttpRequest, textStatus, errorThrown) {
         }
     });
});

在SamplingsDto,

receptionDate是LocalDate dataType

我得错误

  

2018-05-19 14:03:49.824 WARN 12422 --- [nio-8080-exec-3]   .w.s.m.s.DefaultHandlerExceptionResolver:已解决的异常导致   由Handler执行:   org.springframework.http.converter.HttpMessageNotReadableException:   JSON解析错误:无法识别的令牌&receiveDate':正在等待   (' true',' false'或' null');嵌套异常是   com.fasterxml.jackson.core.JsonParseException:无法识别的令牌   ' receptionDate':期待(' true',' false'或' null')at at   [来源:( PushbackInputStream); line:1,column:15]

编辑img数据 enter image description here

0 个答案:

没有答案