【Java】@Produces注解翻译

import javax.ws.rs.Produces;

/*
 * Produces.java
 * Created on September 15, 2006, 2:40 PM
 */

package javax.ws.rs;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * Defines the media type(s) that the methods of a resource class or
 * {@link javax.ws.rs.ext.MessageBodyWriter} can produce.
 * If not specified then a container will assume that any type can be produced.
 * Method level annotations override a class level annotation. A container
 * is responsible for ensuring that the method invoked is capable of producing
 * one of the media types requested in the HTTP request. If no such method is
 * available the container must respond with a HTTP "406 Not Acceptable" as
 * specified by RFC 2616.
 *
 * 

A method for which there is a single-valued Produces * is not required to set the media type of representations that it produces: * the container will use the value of the Produces when * sending a response.

* * @see javax.ws.rs.ext.MessageBodyWriter */ //定义了资源类型或者MessageBOdyWriter的媒体类型产生方法;如果没有特别声明,那么一个容器会认定任何类型都可以被生产; //方法的注解级别重写了类注解级别;一个容器会为保证被引用的方法而负责,从而能够生产一个HTTP请求中的请求媒体类型。如果没有这样一个方法,容器会响应HTTP一个“406 Not Acceptable”信息; //一个有单值的Produces的方法不会被要求设置代表他生产的媒体类型:当发送response请求的时候,容器会使用Produces的值。详情请见javax.ws.rs.ext.MessageBodyWriter @Inherited @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) public @interface Produces { /** * A list of media types. Each entry may specify a single type or consist * of a comma separated list of types. E.g. {"image/jpeg,image/gif", * "image/png"}. Use of the comma-separated form allows definition of a * common string constant for use on multiple targets. * 一系列的媒体类型。每一个入口可能特别规定了一个单独类型或者用逗号隔开一系列类型;例如{"image/jpeg,image/gif", * "image/png"} * 使用逗号分隔的形式允许定义一个普通的string类型的常量,来使用多媒体目标 */ String[] value() default "*/*"; }

你可能感兴趣的:(【基础】)