This demo sourced from the jersey tutor. https://jersey.java.net/documentation/latest/jaxrs-resources.html#d0e1433 provides the necessary info for you.

HelloWorldResource.java

package com.example;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.DefaultValue;
/**
*
* @author
*/
@Path("helloworld")
public class HelloWorldResource {
public static final String CLICHED_MESSAGE = "Hello World!";
/*
@GET
@Produces("text/plain")
public String getHello() {
return CLICHED_MESSAGE;
}
*/
@GET
@Path("/get")
@Produces("text/plain")
//@Produces("application/json")
public String getQueryObj(
@QueryParam ("featureID") @DefaultValue("0") String fid,
@QueryParam ("userID") @DefaultValue( "0" ) int uid,
@QueryParam ("color") @DefaultValue("red") ColorParam clr
// color default value: green, blue
) {
return new String("QueryParam: {"+ fid + ": " + uid + " : " + clr + "}." + CLICHED_MESSAGE);
} }

ColorParam.java

package com.example;
import java.awt.Color;
import javax.ws.rs.WebApplicationException;
import java.lang.reflect.Field; public class ColorParam extends Color { public ColorParam(String s) {
super(getRGB(s));
} private static int getRGB(String s) {
if (s.charAt(0) == '#') {
try {
Color c = Color.decode("0x" + s.substring(1));
return c.getRGB();
} catch (NumberFormatException e) {
throw new WebApplicationException(400);
}
} else {
try {
Field f = Color.class.getField(s);
return ((Color)f.get(null)).getRGB();
} catch (Exception e) {
throw new WebApplicationException(400);
}
}
}
}

Call it after the above java files are packaged as a war deployed in tomcat container.

http://hostname:8080/simple-service-webapp/webapi/helloworld/get?featureID=12
QueryParam: {12: 0 : com.example.ColorParam[r=255,g=0,b=0]}.Hello World! http://hostname:8080/simple-service-webapp/webapi/helloworld/get?featureID=12&userID=123
QueryParam: {12: 123 : com.example.ColorParam[r=255,g=0,b=0]}.Hello World! http://hostname:8080/simple-service-webapp/webapi/helloworld/get?featureID=12&userID=123&color=yellow
QueryParam: {12: 123 : com.example.ColorParam[r=255,g=255,b=0]}.Hello World!

[REST Jersey] @QueryParam Demo的更多相关文章

  1. [接口服务] Jersey Rest Demo

    http://files.cnblogs.com/files/avivaye/RestProject.rar

  2. jersey构建rest服务返回json数据

    1.  eclipse 创建 dynamic web project 2.  将jersey相关jar包放到libs目录下 3. web.xml 增加 jersey 相关内容 <?xml ver ...

  3. 通过mybatis读取数据库数据并提供rest接口访问

    1 mysql 创建数据库脚本 -- phpMyAdmin SQL Dump -- version 4.2.11 -- http://www.phpmyadmin.net -- -- Host: lo ...

  4. Jersey RESTful WebService框架学习(三)使用@QueryParam

    介绍:@QueryParamuri路径请求参数写在方法的参数中,获得请求路径附带的参数.比如:@QueryParam("desc") String desc 前端控制 <!D ...

  5. Spring集成Jersey开发(附demo)

    下文将会初步介绍如何在Spring中集成Jersey,并附简单的demo 所依赖的技术版本: Jersey 1.8 Spring 3.0.5.RELEASE 1. 项目依赖 pom.xml定义(注意去 ...

  6. Jersey 写restful接口时QueryParam ,FormParam 等的区别

    今天用jersey写接口,发现有一个post方法中没有得到参数,查了半天发现自己一不小心将@formparam写成了@queryparam,真是一个悲伤的故事.在这里把几个参数类型整理了一下放出来. ...

  7. jersey简单总结与demo

    参考链接:https://www.iteye.com/blog/dyygusi-2148029?from=singlemessage&isappinstalled=0 测试代码: https: ...

  8. Jersey的RESTful简单案例demo

    REST基础概念: 在REST中的一切都被认为是一种资源. 每个资源由URI标识. 使用统一的接口.处理资源使用POST,GET,PUT,DELETE操作类似创建,读取,更新和删除(CRUD)操作. ...

  9. Java完成最简单的WebService创建及使用(REST方式,Jersey框架)

    前言: 一直以来都对WebService感兴趣,但因为难以理解WebService到底是什么,所以了解甚少.周二的时候有个跟我关系比较好的同事想要自己写个WebService的小Demo,希望能够做成 ...

随机推荐

  1. HTML5的本地存储功能,值得研究

    https://developer.chrome.com/apps/offline_storage 搜索“chrome html5 本地缓存”,一大堆文章,比如: http://www.cnblogs ...

  2. iOS SDK:预览和打开文档

    iOS中的沙盒可以让平台更加的安全,这也是沙盒给用户带来的最主要好处.不过由于沙盒的严格限制,导致程序之间共享数据比较麻烦.一般在程序间共享文档可以通过UIDocumentInteractionCon ...

  3. HDU4731+找规律

    规律题!!! /* */ #include<algorithm> #include<iostream> #include<string.h> #include< ...

  4. 十句话教你学会Linux数据流重定向

    1.看到重定向一下子就想起了web里面的redirect,没错,但是Linux数据流重定向的作用不是跳到另一个网页,而是用来存储重要的屏幕信息.将不必要的屏幕信息输出到文件里或者“黑洞”里.将错误信息 ...

  5. VMware Workstation9安装Mac OS X10.9系统

    链接地址:http://jingyan.baidu.com/article/aa6a2c142cef740d4c19c426.html VMware Workstation9.0安装Mac OS X1 ...

  6. [Swust OJ 247]--皇帝的新衣(组合数+Lucas定理)

    题目链接:http://acm.swust.edu.cn/problem/0247/ Time limit(ms): 1000 Memory limit(kb): 65535   Descriptio ...

  7. C语言深度剖析---const关键字(转载)

    const是constant的缩写,是恒定不变的意思.被const修饰的值,是只读变量. 1.const修饰只读变量,具有不变性      #include <stdio.h> int m ...

  8. HttpResponseRedirect VS HttpResponse

    当我们处理了post提交的数据之后,我们使用HttpResponseRedirect跳转到另一个页面,而不是用HttpResponse. 例如当一个投票环节时使用HttpResponse可以使用浏览器 ...

  9. 使用Maven打包项目并上传到Linux服务器

    Maven打包: 项目右键Run as-->Maven build...-->  出来下面的界面,注意红色部分的填写,Goals填写package表示打包,下面的Skip Tests表示打 ...

  10. c++ namespace命名空间详解

    What is a namespace? A namespace defines an area of code in which all identifiers are guaranteed to ...