本文主要是介绍Jersey请求时服务端接收参数所用注解类型,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
get请求服务器接收参数:@PathParam 请求方式为:http://localhost:8080/resourceRest-1/api/test/2011/11/12
get请求服务器接收参数:@QueryParam 请求方式为:http://localhost:8080/resourceRest-1/api/test/getMessage?from=10&to=100
post请求服务器接收参数:@FormParam
get请求服务器接收参数(参数全部拼接再url后面,post实体里参数为空):@QueryParam
请求:http://localhost:8080/resourceRest-1/api/test/getMessage?from=10&to=100
接收:
@Path("/test")
public class RestTest1 {
@GET
@Path("/getMessage")
@Produces({ MediaType.APPLICATION_JSON }) //制定返回类型为json
public HashMap getClientedMessage(@QueryParam("from") int from, @QueryParam("to") int to) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("abc", "def");
map.put("abc1", ""+from);
map.put("abc2", ""+to);
return map;
}
}
更多参考:
http://www.jianshu.com/p/ac01105241bf
这篇关于Jersey请求时服务端接收参数所用注解类型的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!