前台向后台传一个id数组一个对象
前台代码
save (){
this.pojo.status = 1;
axios.post(`/admin/${this.pojo.id == null ? `add.do?ids=${this.ids}` : `update.do?ids=${this.ids}`}`, this.pojo).then(response => {
this.fetchData (); //刷新列表
this.formVisible = false ;//关闭窗口
});
},
后台代码
@Reference
private RoleService roleService;
@PostMapping("/add")
public Result add(@RequestParam("ids") String[] ids, @RequestBody Admin admin){
List<Role> roleList = new ArrayList<Role>();
for (String id : ids) {
Role role = roleService.findById(Integer.valueOf(id));
roleList.add(role);
}
adminService.add(new AdminRoleList(admin, roleList));
return new Result();
}
后台代码中@RequestBody获取请求体中参数