后端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”),实体类日期格式截图: