title: convert ModelAndView object to []byte array
body: <p>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 ?</p>
  <pre><code>@GetMapping(&quot;/exports/multiple-lists&quot;)
      private ModelAndView getExportExcelMultipleLists() {
          Map&lt;String, Object&gt; model = new HashMap&lt;&gt;();
          Map&lt;String, List&gt; multipleList = new HashMap&lt;&gt;();
          multipleList.put(&quot;test1 shhet&quot;, DataGenerator.generatePopulatedObjects(ExportClassExample.class, 10));
          multipleList.put(&quot;test2 shhet&quot;, DataGenerator.generatePopulatedObjects(IdExportClassExample.class, 10));
          multipleList.put(&quot;test3 shhet&quot;, DataGenerator.generatePopulatedObjects(ExportClassExample.class, 100));
          model.put(ExcelGenerator.MULTIPLE_DATA_LIST, multipleList);
        
          return new ModelAndView(new ExcelGenerator(), model);
      }
  </code></pre>