把JSON存進資料庫的欄位, 要做以下的設置
@Entity(name = "patient_xxx")
@TypeDef(name = "json", typeClass = JsonType.class)
public class PatientXXX {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
// 傳送Json內容
@Type(type = "json")
@Column(name = "content", columnDefinition = "json")
private String content;
...
}
另外, 接值進來的時候, 要用ObjectMapper轉成字串
@PostMapping("/lab/PutStatus")
public JwtResponseResult putStatus(@RequestBody PutStatusRequestVo putStatusRequestVo) {
try {
ObjectMapper mapper = new ObjectMapper();
String jsonString = mapper.writeValueAsString(putStatusRequestVo);
labService.updatePatientExamineOrder(putStatusRequestVo.getExamList());
labService.recordCallApiLog(
putStatusRequestVo.getLab_id(),
jsonString,
PatientExamineLogEnum.Receive.getCode(),
"OK");
} catch (Exception ex) {
ex.printStackTrace();
return new JwtResponseResult("fail", messageHelper, "common.error", ex.getMessage());
}
return new JwtResponseResult("ok", null);
}
***如果直接VO.toString()的話, 是沒辦法列印成做成JSON結構的
沒有留言:
張貼留言