JAX-RS @MatrixParam-Beispiel

Matrixparameter sind im URI-Pfad ein Satz von " name = value "

…​./books/2011;author=mkyong

In der obigen URI lautet der Matrixparameter "**  author = mkyong ** ", getrennt durch ein Semikolon "** ; ** ".

===  1. @MatrixParam-Beispiel

Ein vollständiges Beispiel für die Verwendung von @ MatrixParam in JAX-RS.

import javax.ws.rs.GET; import javax.ws.rs.MatrixParam; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.Response;

@Path("/books") public class BookService {

@GET
@Path("{year}")
public Response getBooks(@PathParam("year") String year,
        @MatrixParam("author") String author,
        @MatrixParam("country") String country) {
return Response
    .status(200)
    .entity("getBooks is called, year : " + year
        + ", author : " + author + ", country : " + country)
    .build();
}

}

Siehe folgende URI-Muster und -Ergebnisse.

{leer} 1. URI-Muster: "** /books/2011/** "

getBooks is called, year : 2011, author : null, country : null

{leer} 2. URI-Muster: "** /books/2011; Autor = mkyong ** "

getBooks is called, year : 2011, author : mkyong, country : null

{leer} 3. URI-Muster: "** /books/2011; Autor = mkyong; Land = Malaysia ** "

getBooks is called, year : 2011, author : mkyong, country : malaysia

{leer} 4. URI-Muster: "** /books/2011; Land = Malaysia; Autor = Mykyong ** "

getBooks is called, year : 2011, author : mkyong, country : malaysia

===  Quellcode herunterladen

Download es - link://wp-content/uploads/2011/07/JAX-RS-MatrixParam-Example.zip[JAX-RS-MatrixParam-Example.zip](6 KB)

===  Referenzen

. http://jsr311.java.net/nonav/releases/1.1/javax/ws/rs/MatrixParam.html[JAX-RS

MatrixParam JavaDoc]

Link://Tag/Jax-RS/[Jax-RS]Link://Tag/Parameter/[Parameter]