作者:張艷濤
time:2020-07-31
SpingMVC
一、前台傳數組,SpingMVC用addusers(@RequestBody List<UserPojo> userlist){ 接收
前台vue發送的數據
let data = [this.form] this.apiPost('acountmanage/addusers', data).then((res) => { this.handelResponse(res, (data) => { _g.toastMsg('success', '添加成功') _g.clearVuex('setUsers') setTimeout(() => { this.goback() }, 1500) }, () => { this.isLoading = !this.isLoading }) })
post中發送的格式

即為:[{key:value,K2:V2,....}]
后台接收處理
@ResponseBody
@CrossOrigin
@RequestMapping(value ="/addusers",produces = {"application/json;charset=UTF-8"})
public String addusers(@RequestBody List<UserPojo> userlist){
try {
//List<UserPojo> userlist = (ArrayList<UserPojo>)params.get("usersinfo");
TradeInfo tradeInfo = new TradeInfo();
String tradeType ="ADDUSERS";
tradeInfo.addData("tradeType",tradeType);
tradeInfo.addData("addusers",userlist);

說明:這里能看到 spring 已經識別到了List數據,並且將{} 轉換成了一個UserPojo對象
