title: Spring RedirectAttributes: addAttribute() vs addFlashAttribute()
body: <p>My understanding so far is on our controller request mapping method we can specify <em>RedirectAttributes</em> parameter and populate it with attributes for when the request gets redirected.</p>
  
  <p><em>Example</em>:</p>
  
  <pre><code>@RequestMapping(value="/hello", method=GET)
  public String hello(RedirectAttributes redirAttr)
  {
     // should I use redirAttr.addAttribute() or redirAttr.addFlashAttribute() here ?
  
     // ...
  
     return "redirect:/somewhere";
  }
  </code></pre>
  
  <p>The redirect attributes will then be available on the target page where it redirects to.</p>
  
  <p>However <em>RedirectAttributes</em> class has two methods:</p>
  
  <ul>
  <li><a href="https://docs.spring.io/spring/docs/5.0.x/javadoc-api/org/springframework/web/servlet/mvc/support/RedirectAttributes.html#addAttribute-java.lang.Object-" rel="noreferrer"><code>addAttribute()</code></a></li>
  <li><a href="https://docs.spring.io/spring/docs/5.0.x/javadoc-api/org/springframework/web/servlet/mvc/support/RedirectAttributes.html#addFlashAttribute-java.lang.Object-" rel="noreferrer"><code>addFlashAttribute()</code></a></li>
  </ul>
  
  <p>Have been reading Spring documentation for a while but I'm a bit lost. What is the fundamental <em>difference</em> between those two, and how should I choose which one to use?</p>