title: Spring : binding object with and without @ModelAttribute
body: <p>I am new in Spring and registering a user.I did like this.</p>
  
  <pre><code>@RequestMapping("/register")
      public String register(@ModelAttribute User user,BindingResult result){
         if(!result.hasErrors()){
           userSerive.register(user);
         }
       return "welcome";
  }
  </code></pre>
  
  <p>This worked fine,but problem here is I don't need this <code>user</code> object in my <code>welcome.jsp</code> page,so why make model object heavier.So I tried without <code>@ModelAttribute</code>, this also works for me like below.</p>
  
  <pre><code>@RequestMapping("/register")
      public String register(User user,BindingResult result){
         if(!result.hasErrors()){
           userSerive.register(user);
         }
       return "welcome";
  }
  </code></pre>
  
  <p>So I just want to know what are pros &amp; cons of both and <strong>which is the best practice if I really don't need <code>user</code> object in <code>jsp</code>.</strong> Is <code>@ModelAttribute</code> does any other thing apart from adding object to Model,which spring implicit binding not does.Is <code>@ModelAttribute</code> safer way of binding or else?</p>
  
  <p>I want to categories my query in following 4 type of request.what would be difference  with and without <code>@ModelAttribute</code> if I need not to send data in view and my request is any of-</p>
  
  <ol>
  <li>query string ie form data in GET</li>
  <li>request payload or body ie form data in POST</li>
  <li>json data in ajaxified GET requst</li>
  <li>json data in POST requst- I guess this would not be bind in any of both. <code>@RequestBody</code> is required.</li>
  </ol>