JAX-RS 注解支持
支持的注解
@Path
@GET
@POST
@PUT
@DELETE
@HEAD
@PATCH
@OPTIONS
@Consumes
@Produces
@QueryParam
@PathParam
@HeaderParam
@MatrixParam
@CookieParam
@FormParam
@BeanParam
@DefaultValue
Note
现阶段Restlight
仅实现了JAX-RS
的注解, 其余功能暂未实现(Provider
, Request
, Response
)等暂不支持
注解使用
@QueryParam
, @PathParam
,@HeaderParam
,@MatrixParam
, @MatrixVariable
,@FormParam
参数绑不支持javax.ws.rs.ext.ParamConverterProvier
扩展
个别注解说明
@QueryParam
除普通用法外, 当未指定value()
或者name
且参数对象为Map<String, List<String>
类型时, 将整个ParameterMap(即AsyncRequest.getParameterMap)作为参数的值。
eg.
public void foo(@QueryParam Map<String, List<String> params) {
//...
}
Note
除url中的参数之外同时支持Post中Content-Type为application/x-www-form-urlencoded的form表单参数@CookieParam
普通String
类型
public void foo(@CookieParam String c) {
//...
}
Cookie
对象(io.netty.handler.codec.http.cookie.Cookie)
public void foo(@CookieParam Cookie c) {
//...
}
获取所有的Cookie
public void foo(@CookieParam Set<Cookie> cookies) {
//...
}
Note
不支持JAX-RS
中的jax.ws.rs.core.Cookie
, 仅支持io.netty.handler.codec.http.cookie.Cookie
@HeaderParam
除获取单个header之外, 可以如果参数类型为io.netty.handler.codec.http.HttpHeaders
则以所有的Header作为参数的值
eg:
public void foo(@HeaderParam HttpHeaders headers) {
//...
}
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.
Last modified March 10, 2022: introduce docsy as the website framework and add docs-v1.0.0 (#120) (79630ff)