JAX-RS @QueryParam@MatrixParam有什么区别?
从文档中,queryparam和matrixparam都可以在特殊条件下定位一个资源。那么用例有什么区别?

ps:

Queryparam:
url ? key=value;
矩阵参数
url; key=value;

最佳答案

this Oracle documentation中所述:



示例(摘自here):

@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();

    }

}

请参阅以下URI模式和结果:
  • URI模式:“/books/2012/”

    getBooks被调用,年份:2012,作者:null,国家/地区:null
  • URI模式:“/books/2012; author = andih”

    名为getBooks,年份:2012,作者:andih,国家/地区:空
  • URI模式:“/books/2012; author = andih; country = germany”

    getBooks被称为,年份:2012,作者:andih,国家/地区:德国
  • URI模式:“/books/2012; country =德国; author = andih”

    getBooks被称为,年份:2012,作者:andih,国家/地区:德国

  • 对于差异的解释,您可以看看
    URL matrix parameters vs. request parameters

    关于java - JAX-RS中的QueryParam和MatrixParam有什么区别?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10183875/

    10-11 22:44
    查看更多