日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

update字段变更SpringBoot @JsonProperty的使用属性的名称序列化为另外一个名称

發布時間:2023/12/3 javascript 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 update字段变更SpringBoot @JsonProperty的使用属性的名称序列化为另外一个名称 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

?

https://blog.csdn.net/wtb617806038/article/details/86093301

?

Restful 接口調用Json接收相關問題

1、背景:

在項目上使用SpringBoot為框架,調用第三方接口時,返回的參數類型,不符合標準的命名規則,需要進行處理,接受數據

2、現象:

調用第三方接口返回數據格式為方式均為小寫,如下:

? ? ? ? ? {
????????????"rowid": "111111",
????????????"created": "2018-12-27 16:15:25",
????????????"createdby": "1111111",
????????????"lastupd": "2018-12-27 08:25:48",
????????????"lastupdby": "111111",
????????????"modificationnum": 1
????????? }
返回Json參數字段均為小寫,在接收時,需要按照標準的命名規則進行映射

3、解決辦法:

創建接收數據對象,生成Get\Set方法:,在Set方法上,加上@JsonProperty注解,

@JsonProperty 此注解用于屬性上,作用是把該屬性的名稱序列化為另外一個名稱,如把rowId屬性序列化為rowid,@JsonProperty("rowid")。

????private String rowId;
????private Date created;
????private String createdBy;
????private Date lastUpd;
? ? private String lastUpdBy;
?
? ? @JsonProperty("rowId")
????public String getRowId() {
????????return rowId;
??? }
?
????@JsonProperty("rowid")
????public void setRowId(String rowId) {
????????this.rowId = rowId;
??? }
?
????public Date getCreated() {
????????return created;
??? }
????@JsonDeserialize(using = CustomJsonDateDeserializer.class)
????public void setCreated(Date created) {
????????this.created = created;
??? }
?
????@JsonProperty("createdBy")
????public String getCreatedBy() {
????????return createdBy;
??? }
?
????@JsonProperty("createdby")
????public void setCreatedBy(String createdBy) {
????????this.createdBy = createdBy;
??? }
以上,就會將數據進行自動映射,獲取到數據

?


————————————————
版權聲明:本文為CSDN博主「小飛萌」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/wtb617806038/article/details/86093301

總結

以上是生活随笔為你收集整理的update字段变更SpringBoot @JsonProperty的使用属性的名称序列化为另外一个名称的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。