title: Spring MVC: how to indicate whether a path variable is required or not?
body: <p>I am doing a Spring web. For a controller method, I am able to use RequestParam to indicate whether a parameter it is required or not. For example:</p>
  
  <pre><code>@RequestMapping({"customer"}) 
  public String surveys(HttpServletRequest request, 
  @RequestParam(value="id", required = false) Long id,            
  Map&lt;String, Object&gt; map)
  </code></pre>
  
  <p>I would like to use PathVariable such as the following:</p>
  
  <pre><code>@RequestMapping({"customer/{id}"}) 
  public String surveys(HttpServletRequest request, 
  @PathVariable("id") Long id,            
  Map&lt;String, Object&gt; map) 
  </code></pre>
  
  <p>How can I indicate whether a path variable is required or not? I need to make it optional because when creating a new object, there is no associated ID available until it is saved.</p>
  
  <p>Thanks for help!</p>