title: Proper way for passing data from controller to view in spring
body: <p>I have two entities </p>
  
  <pre><code>public class FooEntity1 {
     private Integer id;
     private Collection&lt;FooEntity2&gt; entities;
     //gettrs, setters
  }
  
  public class FooEntity2 {
     private Integer id;
     private String msg;
     private String name;
     //gettrs, setters
  }
  </code></pre>
  
  <p>In controller I have an object 'foo' of class FooEntity1 which has a few objects in collection 'entities'.</p>
  
  <p>In JSP file I'd like to do something like this</p>
  
  <pre><code>&lt;c:forEach items="${foo.entities}" var="entity"&gt;
    ${entity.id} - ${entity.msg} - ${entity.name}
  &lt;/c:forEach&gt;
  </code></pre>
  
  <p>I know that it's bad idea to pass entity object to jsp file, so here my question: what is proper way for using data from entities in view? I have two ideas:</p>
  
  <ol>
  <li>put data from entities in Map and pass it to view </li>
  <li>create FooEntity1Dto and FooEntity2Dto classes to pass data to view</li>
  </ol>
  
  <p>How should I do that?</p>