JAX-RS中QueryParam和MatrixParam有什么区别? [英] What's the difference between QueryParam and MatrixParam in JAX-RS?

查看:136
本文介绍了JAX-RS中QueryParam和MatrixParam有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JAX-RS @QueryParam @MatrixParam 之间有什么区别?
来自文档.Queryparam和matrixparam都可以在特殊条件下定位一个资源。那么用例差异是什么?

What's the difference between the JAX-RS @QueryParam and @MatrixParam? From the documents.The queryparam and matrixparam both can location one resource in special condition. So what's the use case difference?

ps:

Queryparam:

Queryparam:

url? key = value;

Matrixparam

Matrixparam

url; key = value;

推荐答案

此Oracle文档


@PathParam 和其他基于参数的注释,
@MatrixParam @HeaderParam @CookieParam @FormParam 服从
@QueryParam 相同的规则。 @MatrixParam
网址路径段中提取信息。 @HeaderParam 从HTTP
标头中提取信息。 @CookieParam 从与cookie相关的HTTP标题中声明为
的cookie中提取信息。

The @PathParam and the other parameter-based annotations, @MatrixParam, @HeaderParam, @CookieParam, @FormParam obey the same rules as @QueryParam. @MatrixParam extracts information from URL path segments. @HeaderParam extracts information from the HTTP headers. @CookieParam extracts information from the cookies declared in cookie related HTTP headers.

示例(摘自此处):

Example (drawn from 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模式和结果:

See following URI patterns and result:


  1. URI模式:/ books / 2012 /

getBooks被调用,年份:2012,作者:null,country:null

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

URI模式: / books / 2012; author = andih

getBooks被调用,年份:2012年,作者:andih,country:null

getBooks is called, year : 2012, author : andih, country : null

URI模式:/ books / 2012; author = andih; country = germany

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

getBooks is called, year : 2012, author : andih, country : germany

URI模式:/ books / 2012; country = germany; author = andih

getBooks被调用,年份:2012,作者:andih,国家:德国

getBooks is called, year : 2012, author : andih, country : germany

有关差异的解释,您可以查看
URL矩阵参数与请求参数

For an explanation of the difference you may have a look at URL matrix parameters vs. request parameters

这篇关于JAX-RS中QueryParam和MatrixParam有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆