RESTEasy常用注解
/**
* @功能描述: (Path中的参数可以是固定值)
*/
@GET
@Path("test-get-param")
@Produces(MediaType.APPLICATION_JSON)
public Map<String, Object> getNotParam() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("say:", new Date());
return map;
} /**
* @功能描述: (Path中的参数可以是正则表达式)
*/
@Path("{id}")
@GET
@Produces("text/plain; charset=utf-8")
public String getPathParam(@PathParam(value = "id") int id) {
return "您好,您输入的数字为:" + id;
} /**
* @功能描述: (Path中的参数可以是多个正则表达式的组合)
*/
@Path("{first}_{last}")
@GET
@Produces("application/json; charset=utf-8")
public String getMorePathParam(@PathParam(value = "first") String first,
@PathParam(value = "last") String last) {
return "输入的信息为,first:" + first + ";last:" + last;
}
二、@GET,@PUT,@POST,@DELETE,标注方法是用的HTTP请求的类型
/**
* @功能描述: (使用MatrixParam参数,在使用正则表达式方式入参时,
* 部分参数和Path中无法匹配时,使用MatrixParam获取)
*/
@GET
@Path("{model}--{year}")
@Produces("text/plain; charset=utf-8")
public String getMatrixParam(@MatrixParam(value = "color") String color,
@PathParam(value = "year") String year,
@PathParam(value = "model") String model) { return "color: " + color + "; year: " + year + "; model: " + model;
}
参数为:color: black; year: context; model: test
/**
* @功能描述: (Context获取Path路径,Matrix参数,PathParam参数)
*/
@GET
@Path("test-context/{id}")
@Produces("text/plain; charset=utf-8")
public String getContext(@Context UriInfo uriInfo) {
String path = uriInfo.getPath();
List<PathSegment> lsps = uriInfo.getPathSegments();
String psString = "";
for (PathSegment ps : lsps) {
psString = psString + JSON.toJSONString(ps) + "; ";
}
MultivaluedMap<String, String> map = uriInfo.getPathParameters();
return "path:" + path + "; lsps:" + psString + "; map:"
+ JSON.toJSONString(map);
} <span style="color:#808080;"> </span><span style="font-family:'Microsoft YaHei UI';font-size:10.5pt; line-height:1.5"> </span>
RESTEasy常用注解的更多相关文章
- Spring系列之Spring常用注解总结
传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点:1.如果所有的内容都配置在.xml文件中,那么.xml文件将会十分庞大:如果按需求分开.xml文件 ...
- SpringMVC常用注解實例詳解3:@ResponseBody
我的開發環境框架: springmvc+spring+freemarker開發工具: springsource-tool-suite-2.9.0JDK版本: 1.6.0_29tomcat ...
- SpringMVC常用注解實例詳解2:@ModelAttribute
我的開發環境框架: springmvc+spring+freemarker開發工具: springsource-tool-suite-2.9.0JDK版本: 1.6.0_29tomcat ...
- Spring常用注解汇总
本文汇总了Spring的常用注解,以方便大家查询和使用,具体如下: 使用注解之前要开启自动扫描功能 其中base-package为需要扫描的包(含子包). <context:component- ...
- Spring常用注解,自动扫描装配Bean
1 引入context命名空间(在Spring的配置文件中),配置文件如下: xmlns:context="http://www.springframework.org/schema/con ...
- springmvc常用注解与类型转换
springmvc常用注解与类型转换 一:前置 spring -servlet.xml 注入 <!-- 启用spring mvc 注解 --> <context:annotation ...
- SpringMVC常用注解,返回方式,路径匹配形式,验证
常用注解元素 @Controller 标注在Bean的类定义处 @RequestMapping 真正让Bean具备 Spring MVC Controller 功能的是 @RequestMapping ...
- SpringMVC 常用注解
本文参考了博客,具体请见:http://www.cnblogs.com/leskang/p/5445698.html Spring MVC的常用注解 1.@Controller @Controller ...
- spring注解开发中常用注解以及简单配置
一.spring注解开发中常用注解以及简单配置 1.为什么要用注解开发:spring的核心是Ioc容器和Aop,对于传统的Ioc编程来说我们需要在spring的配置文件中邪大量的bean来向sprin ...
随机推荐
- css position: relative,absolute具体解释
关于CSS中 position在布局中非常重要,查了非常多资料都说的非常难理解.以下说说个人的理解: 语法: position: relative | absolute relative: 对象遵循常 ...
- CONVERT_DATE_INPUT
[转自http://www.cnblogs.com/VerySky/articles/2226862.html] 通过 Function Module 将外部日期转换为内部日期所属 Function ...
- php......调研投票练习
调研题目与调研选项显示页面<style type="text/css"> #list{ width:400px; height:200px;} #jieguo{ wid ...
- c的详细学习(4)选择结构与循环结构的编程练习
本节介绍c语言的编程实例. (1)求方程ax^2+bx+0的解: 方程有解有以下几种可能: 1.b^2-4ac=0,方程有两个相等实根. 2.b^2-4ac>0,方程有两个不等实 ...
- 剑指offer——不能被继承的类
方法一:通过将类的构造函数和析构函数声明成private来防止子类继承.声明静态的方法来构造和析构类的对象. 但是用起来不是很方便.只能得到在堆上的实例,而不能得到在栈上的实例. 方法二:构造辅助类C ...
- Storm bolt重复消费问题解决
最近碰到一个storm的坑, 两个bolt都需要从kafkaSpout中获取数据进行各自的业务处理, bolt1的处理是幂等的, bolt2的处理是非幂等的, 上线后发现非幂等的bolt处理总是会处理 ...
- CDH- 集群时间同步ntp问题解决
在CDH集群中发现有两台机器获取不到心跳(),导致监控不了机器状态,出现告警 可以使用ntpstat检查与ntp 服务器的时间偏差状态 使用 ntpstat 发现没有同步到ntp时间服务器,运行 nt ...
- Codeforces 163A Substring and Subsequence:dp【子串与子序列匹配】
题目链接:http://codeforces.com/problemset/problem/163/A 题意: 给你两个字符串a,b,问你有多少对"(a的子串,b的子序列)"可以匹 ...
- R基础之批处理--R IN ACTION
1.5 批处理多数情况下,我们都会交互式地使用R:在提示符后输入命令,接着等待该命令的输出结果.偶尔,我们可能想要以一种重复的.标准化的.无人值守的方式执行某个R程序,例如,你可能需要每个月生成一次相 ...
- Memcached 分布式缓存实现原理简介
摘要 在高并发环境下,大量的读.写请求涌向数据库,此时磁盘IO将成为瓶颈,从而导致过高的响应延迟,因此缓存应运而生.无论是单机缓存还是分布式缓存都有其适应场景和优缺点,当今存在的缓存产品也是数不胜数, ...