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. Xamarin.Android开发实践(五)

    原文:Xamarin.Android开发实践(五) 一.服务的生命周期 服务与活动一样,在它的整个生命周期中存在着一些事件,下图可以很好解释整个过程以及涉及到的方法: 在真实的使用中,Service来 ...

  2. Android绘图监听接口OnPreDrawListener详解

    public static interface ViewTreeObserver.OnPreDrawListener 我们先看下API中的定义: 类概述: 为即将绘制视图树时执行的回调函数定义的接口. ...

  3. JRebel 6 破解版及使用方法

    最近更新到jrebel6.2.1了,我自己做了个技术分享的微信公众号(茶爸爸),有心的朋友可以来这里一起学习 云盘下载链接: http://pan.baidu.com/s/1bnGzMUF 配置: - ...

  4. poj 1579 Function Run Fun(记忆化搜索+dp)

    题目链接:http://poj.org/problem?id=1579 思路分析:题目给出递归公式,使用动态规划的记忆搜索即可解决. 代码如下: #include <stdio.h> #i ...

  5. Save Princess(丑数)

    Save Princess 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Yesterday, the princess was kidnapped by a de ...

  6. 企业级IM应该帮助员工提高绩效,避免无关的信息干扰

    很多上班族一定熟悉如下的场景: 您早上上班一打开QQ,就弹出一个新闻集成窗口,随便点开看看吧,这一点不要紧,您就被一个又一个的链接带着逛下去了.等回过神来要工作的时候,发现已经在这些八卦新闻上浪费了一 ...

  7. OpenStack里对VPN的支持

    今天翻自己的笔记找到了点去年研究Cloudpipe的东西: 对于用VLAN隔开的项目内主机的访问,可以使用CloudPipe来进行VPN访问 其实就是把OpenStack和OpenVPN集成了一下,给 ...

  8. git 使用过程(四、回退版本)

    1.查看修改历史 命令:git log  如果嫌内容太多 可以加参数  --pretty=oneline (图一) 2.回退 命令:git reset --hard HEAD^    HEAD:代表本 ...

  9. Zend Studio 10.6.0汉化教程(图文)

      来源于:http://www.pw88.com/teach/bangong/32.html 此汉化方法适用于所有的zend studio版本.整个汉化思路是:在线或者离线官方下载汉化包,本地安装即 ...

  10. iOS开发App上传的三大步骤

    上传流程 1.itunse connect中->“我的App”中新建创建应用,填写相关的信息 a.项目名称(多创建几个),避免重名 b.想好应用的类型 c.应用截图(5.5,4.7,4,3.5寸 ...