<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=hal10001" rel="nofollow">Brian Reindel</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-8402?redirect=false" rel="nofollow">SPR-8402</a></strong> and commented</p>
<p dir="auto">For instance:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="@Controller
public class MyController {

	@RequestMapping(value={&quot;/user/id/{id}/delete&quot;, &quot;/user/id/{id}/deleted/{deleted}/delete&quot;}, method=RequestMethod.GET)
	public ModelAndView updateUserHandler(@PathVariable String id, @PathVariable String deleted) {
	
		/* Implementation */
		
	}
}"><pre class="notranslate"><code class="notranslate">@Controller
public class MyController {

	@RequestMapping(value={"/user/id/{id}/delete", "/user/id/{id}/deleted/{deleted}/delete"}, method=RequestMethod.GET)
	public ModelAndView updateUserHandler(@PathVariable String id, @PathVariable String deleted) {
	
		/* Implementation */
		
	}
}
</code></pre></div>
<p dir="auto">That code above will throw an IllegalStateException. Instead, only the following is allowed if I want access to deleted:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="@Controller
public class MyController {

	@RequestMapping(value=&quot;/user/id/{id}/deleted/{deleted}/delete&quot;, method=RequestMethod.GET)
	public ModelAndView updateUserHandler(@PathVariable String id, @PathVariable String deleted) {
	
		/* Implementation */
		
	}
}"><pre class="notranslate"><code class="notranslate">@Controller
public class MyController {

	@RequestMapping(value="/user/id/{id}/deleted/{deleted}/delete", method=RequestMethod.GET)
	public ModelAndView updateUserHandler(@PathVariable String id, @PathVariable String deleted) {
	
		/* Implementation */
		
	}
}
</code></pre></div>
<p dir="auto">However, this necessitates always providing a value for the deleted parameter. This should instead be treated like request.getParameter(), in that if you try to access a request parameter (or path variable in the case of Spring) that doesn't exist on the path, the value defaults to null.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0.5</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398110324" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12639" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12639/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12639">#12639</a> Allow optional <code class="notranslate">@PathVariable</code> (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=senoctar" rel="nofollow">Patras Vlad Sebastian</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-7984?redirect=false" rel="nofollow">SPR-7984</a></strong> and commented</p>
<p dir="auto">Allow mapping the same method to multiple URL's that differ in respect to what path variables they use.<br>
For example we do not want to transfer the id of the logged in user in the URL for security reasons and simplicity, but there are pages that can either show data for the logged in user or an other user, like a profile page.<br>
I would like to be able to map a method like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="@RequestMapping(value = {&quot;/profile&quot;, &quot;/profile/{userId}&quot;})
public String showProfile(@PathVariable(&quot;userId&quot;) Integer userId) {
  if (userId == null) {
    userId = &lt;get id of logged in user from session&gt;;
  }
  //do stuff
}"><pre class="notranslate"><code class="notranslate">@RequestMapping(value = {"/profile", "/profile/{userId}"})
public String showProfile(@PathVariable("userId") Integer userId) {
  if (userId == null) {
    userId = &lt;get id of logged in user from session&gt;;
  }
  //do stuff
}
</code></pre></div>
<p dir="auto">The first path of the request mapping to does not have a "userId" path variable, and it would be nice if userId (the method parameter) would be null in this case, rather than throwing IllegalStateException.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0.5</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398112689" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13049" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13049/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13049">#13049</a> A <code class="notranslate">@PathVariable</code> provided in the method parameter, but not in the <code class="notranslate">@RequestMapping</code>, will throw an IllegalStateException. (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>
<p dir="auto">1 votes, 4 watchers</p>