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