Springboot+vue前后端分离项目axios传递对象数组


在最近做的一个项目里面,涉及到一个批量导出学生信息到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:对象数组})


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM