axios post复杂对象到springboot

2019-06-05  本文已影响0人  cjlynn

1、前端

let roles = [];

if(this.vo.roleIds &&this.vo.roleIds.length >0) {

this.vo.roleIds.forEach(e => {

roles.push({id: e});

//注意此处不能是roles.push({role:{id: e}})

});

}

let params = {

id:this.vo.id,

name:this.vo.name,

uri:this.vo.uri,

queryKey:this.vo.queryKey,

msgType:this.vo.msgType,

roles:roles,

};

//let pars =this.$qs.stringify(params);//不需要stringfy

this.$axios.post("/admin/submsg/save",params).then((res) => {

_this.loading =false;

if (res.data.code ==200) {

_this.$message.success('更新成功');

_this.$router.push("/submsg");

}else {

_this.$message.error('更新失败');

}

});

2、后台

@PostMapping("/save")

public RsJson save(@RequestBody Submsg ps) {

return json(() -> {

submsgService.save(ps);

return null;

});

}

@Data

@Table(name ="submsg")

public class Submsg {

@Id

    private String id;

private String name;

@Transient

    private List<Role> roles;

}

上一篇下一篇

猜你喜欢

热点阅读