日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

前端添加把數組轉為String,后端查詢顯示把String拆分為數組

作者:qq_50031016 更新時間: 2022-03-04 編程語言

前端添加把數組轉為String,后端查詢顯示把String拆分為數組

首先,把頁面準備好,我用的是iview中的

在這里插入圖片描述

**

 - <template>
       <Transfer
           :data="data1"
           :target-keys="targetKeys1"
           :render-format="render1"
           @on-change="handleChange1"></Transfer> </template> <script>
       export default {
           data () {
               return {
                   data1: this.getMockData(),
                   targetKeys1: this.getTargetKeys()
               }
           },
           methods: {
               getMockData () {
                   let mockData = [];
                   for (let i = 1; i <= 20; i++) {
                       mockData.push({
                           key: i.toString(),
                           label: 'Content ' + i,
                           description: 'The desc of content  ' + i,
                           disabled: Math.random() * 3 < 1
                       });
                   }
                   return mockData;
               },
               getTargetKeys () {
                   return this.getMockData()
                           .filter(() => Math.random() * 2 > 1)
                           .map(item => item.key);
               },
               render1 (item) {
                   return item.label;
               },
               handleChange1 (newTargetKeys, direction, moveKeys) {
                   console.log(newTargetKeys);
                   console.log(direction);
                   console.log(moveKeys);
                   this.targetKeys1 = newTargetKeys;
               }
           }
       }

**
</script>

1. 點擊源列表,點擊>鍵,可以選一個或多個,點擊保存, console.log(moveKeys);這個是目的列表中選中的項


##  lowercode:this.moveKeys.join(",")

,  把數組轉為String,用,隔開
```之后的添加正常寫代碼就可以傳入數據庫了,

 **2.** **通過后臺查詢顯示,把String拆分為list的話用split**
  

## Service層

 @Transactional(rollbackFor = Exception.class)
    public VBObjectRelate QueryObjectChildsByCode(String code){
        Optional<ObjectRelateentity> byId = objectRelateRepository.findById(code);
        VBObjectRelate map = mapper.map(byId.get(), VBObjectRelate.class);
        String[] split = map.lowercode.split(",");
        List<String> namaList = new ArrayList<>();
        for (String item:split ) {
            VBObject object = service.get(item);
            namaList.add(object.name);
        }
        map.lowercode = namaList.toString();
        return  map;
    }

## Controller層
 @PostMapping("/query/{code}")
    public VBResponseResutDTO Query(@PathVariable String code){
        VBObjectRelate vbObjectRelate = vbObjectRelateService.QueryObjectChildsByCode(code);
        return  new VBResponseResutDTO(mapper.map(vbObjectRelate,ObjectRelateDao.class));
    }

**## 前端代碼**

     

query(code) {
this.tableData=[];
this.$http.post("/api/bdmp/objectRelate/query/"+this.querycode).then(res => {
if(res!=undefined){
let arr=[];
res.data.lowercode.split(",").forEach(element => {
arr.push({
upcode:res.data.upcode,
name:element,
deleted:res.data.deleted,
createtime:res.data.createtime
})
});
this.tableData = arr;
}
});
},

自己記錄,勿噴!!!!!!!

原文鏈接:https://blog.csdn.net/qq_50031016/article/details/112787723

欄目分類
最近更新