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 ...
随机推荐
- 通过systemd配置Docker
1. systemd Service相关目录 通常情况下,我们有3种方式可以配置etcd中的service.以docker为例,1)在目录/etc/systemd/system/docker.serv ...
- pymysql插入datetime类型
第一种 create_time=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") 第二种 update_time=time ...
- Ruby 循环
Ruby while 语句: 语法: while conditional [do] codeend 执行代码当条件为true时.while循环的条件是代码中的保留字,换行,反斜杠()或一个分号隔开. ...
- Python程序打包成exe的一些坑
今天写了一个项目,Python项目,需要在win7上跑起来,我想,这不是简单的不行么,直接上Pyinstaller不就完了? 但是后来,我发觉我真是too young too simple. 为什么这 ...
- UI控制滑杆插件
在线演示 本地下载
- Hadoop 运行jar包时 java.lang.ClassNotFoundException: Class com.zhen.mr.RunJob$HotMapper not found
错误如下 Error: java.lang.RuntimeException: java.lang.ClassNotFoundException: Class com.zhen.mr.RunJob$H ...
- Codeforces Round #250 (Div. 2) A, B, C
A. The Child and Homework time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Linux- 关于windows和Linux和Mac的换行符
windows 的换行符为"\r\n" Linux的换行符为"\n" Mac的换行符为"\n\r",和Windows相反
- string 中的 length函数 和size函数 返回值问题
string 中的 length函数 和 size函数 的返回值 ( 还有 char [ ] 中 测量字符串的 strlen 函数 ) 应该是 unsigned int 类型的 不可以 和 -1 ...
- css中单位px和em,rem的区别
PX:PX实际上就是像素,用PX设置字体大小时,比较稳定和精确.但是这种方法存在一个问题,当用户在浏览器中浏览我们制作的Web页面时,如果改变了浏览器的缩放,这时会使用我们的Web页面布局被打破.这样 ...