網站首頁 編程語言 正文
前端添加把數組轉為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
相關推薦
- 2022-12-11 React?狀態的不變性實例詳解_React
- 2023-10-28 如何給k8s集群里的資源打標簽_云其它
- 2022-10-09 C#實現選擇排序_C#教程
- 2022-02-02 element ui el-dialog 居中,并且內容多的時候內部可以滾動
- 2022-05-06 Matplotlib安裝與配置
- 2022-05-13 Missing essential plugin: org.jetbrains.androidPle
- 2023-07-08 后端返回svg文件流前端展示并下載
- 2022-07-27 Python編寫條件分支代碼方法_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支