0

I have an API that returns a ModelAndView object having 2 params in the constructor, an ExcelGenerator that I implemented and a map (see below code). Everything is fine , when I access the endpoint in the browser , the excel file is automatically downloaded and rendered accordingly. My question is, I want to attach this file generated, using Attachment() object, to an email, but i do not know how to get the bytes[] out of a ModelAndView object. Has anyone any idea please ?

@GetMapping("/exports/multiple-lists")
    private ModelAndView getExportExcelMultipleLists() {
        Map<String, Object> model = new HashMap<>();
        Map<String, List> multipleList = new HashMap<>();
        multipleList.put("test1 shhet", DataGenerator.generatePopulatedObjects(ExportClassExample.class, 10));
        multipleList.put("test2 shhet", DataGenerator.generatePopulatedObjects(IdExportClassExample.class, 10));
        multipleList.put("test3 shhet", DataGenerator.generatePopulatedObjects(ExportClassExample.class, 100));
        model.put(ExcelGenerator.MULTIPLE_DATA_LIST, multipleList);
      
        return new ModelAndView(new ExcelGenerator(), model);
    }
Marius Pop
  • 158
  • 1
  • 4
  • 20

0 Answers0