在最近做的一个项目里面,涉及到一个批量导出学生信息到excel文件的需求,发现在controller的参数封装不了对象数组,一直是null
解决方案:
我们后端接收采用 String 类型 接收一个json的字符串
前端也就传递给我们一个json数据
在通过处理json数据获取我们想要得到的对象数组
废话不多说上代码
Controller
public Result exportStudents(@RequestBody String students, HttpServletResponse response){ JSONObject jsonObject = JSONObject.parseObject(students); List<StudentDto> studentDtos = JSONObject.parseArray(jsonObject.getJSONArray("students").toJSONString(), StudentDto.class); return null; }
Vue + axios 传参
const{data:res}=await this.$axios.post("/student/exportStudents",{students:对象数组})