---
title: "RESTEasy 系列 Chapter 7 @HeaderParam"
author: "smallplum"
date: "2013-03-28T10:16:22Z"
tags: []
categories: ["开源软件"]
slug: "resteasy-chapter-7-headerparam"
draft: false
lastmod: "2013-03-28T10:16:54Z"
id: 1837817
url: "https://essay.iteye.com/blog/1837817"
---

@HeaderParam注解允许你映射一个HTTP请求的header到你的方法调用。

GET /books?num=5

 

```
@GET    
public String getBooks(@HeaderParam("From") String from) {    ...    }
```

 

类似于PathParam, 

你的参数类型可以是一个字符串，基本类型，或者拥有一个字符串构造方法或静态 valueOf()方法的类。示例中，  MediaType 拥有一个 valueOf() 方法， 你可以这样做：

 

```
@PUT    
public void put(@HeaderParam("Content-Type") MediaType contentType, ...)
```