简体   繁体   English

RESTEasy和JAX-RS之间的区别

[英]Difference between RESTEasy and JAX-RS

What is Resteasy? 什么是Resteasy? what is the difference between RESTEasy and JAX-RS? RESTEasy和JAX-RS有什么区别? What is the difference between @PathParam and @QueryParam ? @PathParam@QueryParam什么@QueryParam

According to its homepage RESTEasy is 根据它的主页 RESTEasy是

... a fully certified and portable implementation of the JAX-RS specification. ... 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。

Query parameters are 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 parameters are 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 路径参数从请求URI中提取,参数名称对应于@Path类级别注释中指定的URI路径模板变量名称。 URI parameters are specified using the javax.ws.rs.PathParam annotation in the method parameter arguments 使用方法参数参数中的javax.ws.rs.PathParam批注指定URI参数

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参数)

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.* packages(它们是Oracle SE 6的一部分,由Oracle提供)。

RESTEasy as well as, for example, Jersey or Apache CXF , are open source implementations of that JAX-RS classes. RESTEasy以及例如JerseyApache CXF是JAX-RS类的开源实现。

During compilation you need only JAX-RS. 在编译期间,您只需要JAX-RS。 In runtime you need only one of that implementations. 在运行时,您只需要其中一个实现。

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 @QueryParam Some great points here regarding params, When to use @QueryParam vs @PathParam - Gareth's answer 关于param的信息, @ PathParam和@QueryParam什么区别这里有关于params的一些重点, 何时使用@QueryParam vs @PathParam - Gareth的答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM