java RESTEasy 和 JAX-RS 的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12471901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 09:02:26  来源:igfitidea点击:

Difference between RESTEasy and JAX-RS

javajax-rsresteasy

提问by user1679378

What is Resteasy? what is the difference between RESTEasy and JAX-RS? What is the difference between @PathParamand @QueryParam?

什么是安逸?RESTEasy 和 JAX-RS 有什么区别?@PathParam和 和有什么不一样@QueryParam

回答by Joachim Sauer

According to its homepageRESTEasy is

根据其主页RESTEasy 是

... a fully certified and portable implementation of the JAX-RSspecification.

... JAX-RS规范的完全认证和可移植实现。

So JAX-RS is a specification of how a library for implementing REST APIs in Java should look like and RESTEasy is one implementation of that specification.

因此,JAX-RS 是一种规范,用于说明在 Java 中实现 REST API 的库应该是什么样子,而 RESTEasy 是该规范的一种实现。

This effectively means that any documentation on JAX-RS should apply 1:1 to RESTEasy as well.

这实际上意味着 JAX-RS 上的任何文档也应该 1:1 应用于 RESTEasy。

回答by Naveenkumar K

Query parametersare extracted from the request URI query parameters, and are specified by using the javax.ws.rs.QueryParam annotation in the method parameter arguments.

查询参数是从请求URI查询参数中提取出来的,在方法参数参数中使用javax.ws.rs.QueryParam注解指定。

Example:

例子:

@Path("smooth")
@GET
public Response smooth(
    @DefaultValue("2") @QueryParam("step") int step,
    @QueryParam("minm") boolean hasMin,
    @QueryParam("test") String test
    ) { ... }

URL: http://domain:port/context/XXX/smooth?step=1&minm=true&test=value


URI path parametersare extracted from the request URI, and the parameter names correspond to the URI path template variable names specified in the @Path class-level annotation. URI parameters are specified using the javax.ws.rs.PathParam annotation in the method parameter arguments

从请求URI中提取URI路径参数,参数名对应@Path类级注解中指定的URI路径模板变量名。URI 参数使用方法参数参数中的 javax.ws.rs.PathParam 注释指定

Example:

例子:

@Path("/{userName}")
public class MyResourceBean {
...
@GET
public String printUserName(@PathParam("userName") String userId) {
    ...
}
}


 URL: http://domain:port/context/XXX/naveen

Here, naveen takes as the userName(Path parameter)

这里,naveen 以 userName(Path 参数)

回答by yegor256

JAX-RS is a set of interfaces and classes without real implementation that belong to javax.ws.rs.*packages (they are part of Java SE 6, by Oracle).

JAX-RS 是一组没有真正实现的接口和类,属于javax.ws.rs.*包(它们是 Oracle 的 Java SE 6 的一部分)。

RESTEasyas well as, for example, Jerseyor Apache CXF, are open source implementations of that JAX-RS classes.

RESTEasy以及例如JerseyApache CXF都是该 JAX-RS 类的开源实现。

During compilation you need only JAX-RS. In runtime you need only one of that implementations.

在编译期间,您只需要 JAX-RS。在运行时,您只需要其中一种实现。

回答by abpan

Please also note that JAX-RS is only server side specification and RESTEasy has extended it to bring JAX-RS to the client side through the RESTEasy JAX-RS Client Framework.

另请注意,JAX-RS 只是服务器端规范,RESTEasy 对其进行了扩展,通过 RESTEasy JAX-RS 客户端框架将 JAX-RS 带到客户端。

Info on param, What is the difference between @PathParam and @QueryParamSome great points here regarding params, When to use @QueryParam vs @PathParam- Gareth's answer

关于 param 的信息, @PathParam 和 @QueryParam 之间有什么区别这里关于 params 的一些要点, 何时使用 @QueryParam 与 @PathParam- Gareth 的回答