資料庫儲存集合格式資料Java
阿新 • • 發佈:2021-10-24
資料庫儲存集合格式資料
接收前端
list
資料轉字串儲存,並查詢,轉為list
格式返回給前端接收前端 list 集合資料,例如圖片陣列等,格式:["efsf/23ff/333.jpg"]
實體類需要欄位
/** * 圖片欄位,用來儲存 **/ @ApiModelProperty(value = "圖片(無需傳值)") private String imgArray; /** * 圖片陣列,和前端資料互動 **/ @Transient @ApiModelProperty(value = "圖片陣列") private String[] imgList;
查詢
package java.lang;
/**
* tbSydwCrk.getImgArray()獲得資料儲存的圖片陣列字串
* 資料庫資料格式: "aaa.webp,bbb.webp,ccc.webp"
* 轉換成:["aaa.webp","bbb,webp","ccc.webp"]
*/
String[] imgList = tbSydwCrk.getImgArray().split(",")
新增
package org.apache.commons.lang3; /** * StringUtils.join(),將陣列或集合以某拼接符拼接到一起形成新的字串 * 將前端資料 ["aaa.webp","bbb,webp","ccc.webp"] * 轉換為 "aaa.webp,bbb.webp,ccc.webp" */ String imgArray = StringUtils.join(tbSydwCrk.getImgList(), ",")