面向服务的架构现在如火如荼,国内常用的当属阿里巴巴开源的dubbo,但我觉得后起之秀的spring cloud很可能弯道超车。闲话说了一些,下面入主题,出问题rest服务接口
@Path("queryList")
//@POST---漏掉@POST注解就会出错
@Override
下面来分析下POST注解:
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@HttpMethod(HttpMethod.POST)
@Documented
public @interface POST {
}
这个里面又涉及到一个主要的注解HttpMethod:
/**
* Associates the name of a HTTP method with an annotation. A Java method annotated
* with a runtime annotation that is itself annotated with this annotation will
* be used to handle HTTP requests of the indicated HTTP method. It is an error
* for a method to be annotated with more than one annotation that is annotated
* with {@code HttpMethod}.
*
* @author Paul Sandoz
* @author Marc Hadley
* @see GET
* @see POST
* @see PUT
* @see DELETE
* @see HEAD
* @since 1.0
*/
@Target({ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface HttpMethod
该接口doc说明概括下来就是:
HttpMethod(或者扩展注解接口)注解的方法会被用来处理相应HTTP请求方法(POST/GET/PUT等)请求,如果漏掉这个注解,那么相应的方法就没有了这个能力!!