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 ...
随机推荐
- FTP开启被动连接模式
在Linux环境下搭建ftp服务器,具体步骤见:http://www.cnblogs.com/zjiacun/p/6896803.html 配置被动连接的方法: 找到配置文件/etc/vsftpd/v ...
- Linux 3 -grep
七. grep家族: 1. grep退出状态: 0: 表示成功: 1: 表示在所提供的文件无法找到匹配的pattern: 2: 表示参数中提供的文件不存在. 见如下示例: /> grep 'ro ...
- Linux系统中UI库curse.h不存在问题——贪吃蛇为例
1. 问题 大家在用Linux写程序时,大家会使用Linux gcc编译器中的头文件curse.h.但往往一般的发行版中都没有默认安装这个头文件,需要大家自行安装.最近遇到这个问题,如下: Red ...
- 第二章 python中重要的数据结构(下)
二.元组(tuple):不可变序列 跟list一样,也是一种序列,唯一不同的是,元组元素不能被修改,通常用(, ,)表示元组,也可以不加括号. #创建元组 >>> 1,2,3 (1, ...
- JS饼状图表数据分布插件
在线演示 本地下载
- Linux 上通过rpm安装mysql
安装mysql之前要remove掉系统自带的mysql: rpm -qa | grep "MySQL*" 和rpm -qa | grep mysql 要确保卸载干净 rpm ...
- etcd -> Highly-avaliable key value store for shared configuration and service discovery
The name "etcd" originated from two ideas, the unix "/etc" folder and "d&qu ...
- [转] 在Mac上搭建React Native开发环境
原文链接: http://blog.csdn.net/xiangzhihong8/article/details/53914336 概述 前面我们介绍过在window环境下开发React Native ...
- logstash的output插件
logstash 的output插件 nginx,logstash和redis在同一台机子上 yum -y install redis,vim /etc/redis.conf 设置bind 0.0.0 ...
- BZOJ 1096 [ZJOI2007]仓库建设:斜率优化dp
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1096 题意: 有n个工厂,从左往右排成一排,分别编号1到n. 每个工厂里有p[i]件产品, ...