title: ModelAndView.addObject vs Model.addAttribute
body: <p>Good day, I'm learning Spring MVC and I'm writting my tiny webapp following <a href="http://www.beingjavaguys.com/2013/07/spring-jdbc-template-with-spring-mvc.html" rel="noreferrer">this tutorial</a> but I slightly modified it as a "list of tasks" and not "list of users". One thing is not clear to me so I'd like to ask for an explanation. This is my edit.jsp:</p>
  
  <pre><code>&lt;%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%&gt;  
  &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%&gt;  
  &lt;%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Edit task&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h1&gt;Edit task&lt;/h1&gt;
      &lt;form:form method="post" action="/update" modelAttribute="task"&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt;Title&lt;/td&gt;
                  &lt;td&gt;&lt;form:input path="title"/&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Description&lt;/td&gt;
                  &lt;td&gt;&lt;form:textarea path="description"/&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="submit" value="Save"/&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/form:form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And this is method editTask in my HomePageController.java (version 1):</p>
  
  <pre><code> @RequestMapping("/edit")  
   public ModelAndView editTask(@RequestParam String id, @ModelAttribute Task task) {  
     // Retrieve task from the database
       task = taskService.getTask(id);
       ModelAndView model = new ModelAndView("edit");
       model.addObject("task", task);
       return model;
   }
  </code></pre>
  
  <p>If I click on edit link to edit an item (e.g. /TaskBook/edit?id=1) a form appears but it is not populated. So I changed the method this way (version 2):</p>
  
  <pre><code> @RequestMapping("/edit")  
   public String editTask(@RequestParam String id, Model model) {
       Task task = taskService.getTask(id);
       model.addAttribute("task", task);
       return "edit";
   }
  </code></pre>
  
  <p>Now the form is populated when I edit a task. I don't understand what's the difference between model.addObject("task", task) in version 1 and model.addAttribute("task", task) in version 2. Is the task object stored somewhere else or is it lost? Please explain. I use Spring Framework 3.2.1.</p>
  
  <p>Thank you in advance. Vojtech.     </p>
  
  <p>EDIT: 
  If I change editTask() to code below it works - the form is populated. But what if some task data were submited, how can I read them now?</p>
  
  <pre><code>@RequestMapping("/edit")  
  public ModelAndView editTask(@RequestParam String id) {  
    task = taskService.getTask(id);
    ModelAndView model = new ModelAndView("edit");
    model.addObject("task", task);
    return model;
  }
  </code></pre>