2022年3月9日 星期三

資料表存JSON格式文字

把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結構的

沒有留言:

張貼留言

[leetcode] [KMP] KMP

ABCDABD... ABCDABF... 簡單的說, 傳統解兩字串匹配部分 可能會來個雙迴圈, 哀個比對, 當不匹配的時候, 會將下方列再後移1位 然後不匹配再後移 然而 如果像上放已經有4個屬於匹配的字串, 她就應該直接往後移四位來匹配, 而不是只移動1位 隱藏的思維是, 當...