<div dir="ltr" style="text-align: justify;" trbidi="on">In this article we will explain in <b>JAX-RS</b>, you can use <b><i>@PathParam </i></b>to inject the value of URI parameter that defined in <i><b>@Path</b></i> expression, into Java method.</p>
<p> <b>1. <i>@PathParam</i> – Single Parameter</b></p>
<p> A simple and normal way to use <i><b>@PathParam</b></i>.</p>
<pre class="highlight" name="code">import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
 
@Path("/employees")
public class EmployeeRestService {
 
 @GET
 @Path("{employeeId}")
 public Response getEmployeeById(@PathParam("employeeId") String employeeId) {
 
 return Response.status(200).entity("getEmployeeById is called, employeeId : " + employeeId).build();
 
 }
 
}
</pre>
<div align='center' id="ads-id"></div>
<p>In above example, the value of {employeeId} from<i><b> &#8220;/employees/{employeeId}&#8221;</b></i> will match to &#8220;<i><b>@PathParam(&#8220;employeeId&#8221;) String var</b></i>&#8220;.</p>
<p> URI Pattern : &#8220;<i><b>/employees/12121&#8243;</b></i></p>
<p> <i><b>getEmployeeById </b></i>is called, <i><b>employeeId : 12121</b></i></p>
<p> <b>2. <i>@PathParam</i> – Multiple Parameters</b></p>
<p> Example to inject multiple parameters into Java method.</p>
<pre class="highlight" name="code">import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
 
@Path("/employees")
public class EmployeeRestService {
 
 @GET
 @Path("{year}/{month}/{day}")
 public Response getEmployeeHistory(
 @PathParam("year") int year,
 @PathParam("month") int month, 
 @PathParam("day") int day) {
 
 String date = year + "/" + month + "/" + day;
 
 return Response.status(200)
 .entity("getEmployeeHistory is called, year/month/day : " + date)
 .build();
 
 }
 
}
</pre>
<p><i><b>URI Pattern : &#8220;/employees/2013/06/16&#8221;</b></i><br />
<i><b><br />
</b></i> <i><b>getEmployeeHistory is called, year/month/day : 2013/06/16</b></i></p>
<p>
<b>Download SourceCode</b><br />
<b><a href="https://sites.google.com/a/dineshonjava.com/dineshonjava/dineshonjava/JAX-RS%20%40Path%20URI%20matching%20example.zip?attredirects=0&;d=1" target="_blank">JAX-RS @Path URI matching example.zip</a></b></p>
<p><i><b>References</b></i><br />
1.<b> <i><a href="http://docs.oracle.com/javaee/6/tutorial/doc/giepu.html" target="_blank">JAVA REST Web Services</a></i></b><br />
2. <i><b><a href="http://en.wikipedia.org/wiki/Web_service" target="_blank">Wikipedia for REST Web Service</a></b></i></p>
<p> ; </p>
<div style="background-color: pink; border-width: thin; text-align: center;"><b><;<;<a href="https://dineshonjava.com/2013/06/jax-rs-path-uri-matching-example.html">Previous </a><;<; ; ; || <a href="https://dineshonjava.com/2013/06/jax-rs-web-service-tutorial.html">Index </a>||  ; >;>;<a href="https://dineshonjava.com/2013/06/jax-rs-queryparam-example.html">Next</a> >;>;</b></div>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/jax-rs-path-uri-matching-example/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/jax-rs-queryparam-example/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '423'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…