後端controller代碼,直接接收NcovPatientReport 對象:
@RequestMapping(value = "/savePatientReport", method = RequestMethod.PUT)
@ApiOperation("患者報告信息保存")
@ApiImplicitParams({})
public ResultModel<NcovPatientReport> savePatientReport(NcovPatientReport report) {
try {
NcovPatientReport patientReport = nvocService.savePatientReport(report);
return ResultModel.success(patientReport);
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getLocalizedMessage(), e);
return ResultModel.failure();
}
}
前端調用接口方式,注意data參數不要stringify:
//患者信息保存
for (var patientItem in patientReport) {
if (patientItem == "upDate"){
debugger
}
patientReport[patientItem] = $(".patInfo").find("input[nameCode="+ patientItem +"]").val()
}
patientReport["sex"] = $("div[nameCode=sex] input:radio:checked").val();
patientReport["ethnic"] = $("select[nameCode=ethnic] option:selected").val();
patientReport["peopleCategoryCode"] = $("select[nameCode=peopleCategoryCode] option:selected").val();
patientReport["clinicalType"] = $("select[nameCode=clinicalType] option:selected").val();
patientReport["upContent"] = $("textarea[nameCode=upContent]").val();
patientReport["diag"] = $("textarea[nameCode=diag]").val();
$.ajax({
url: "/ps/api/ncov/savePatientReport",
dataType: "json",
data:patientReport,
type: "put",
success: function (resp) {
console.log(resp)
}
})
前端效果截圖:
前端調用時加入遇到400錯誤,看看preview裏的錯誤消息:
錯誤是由於前端日期格式和後端日期格式不統一導致的:
此時,在後端實體類中增加註解@DateTimeFormat(pattern = “yyyy-MM-dd”),實體類日期格式截圖: