首页 >社区问答列表 >java自定义注解

java自定义注解

比如springmvc的requestmapping

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package org.springframework.web.bind.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.core.annotation.AliasFor;

@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Mapping
public @interface RequestMapping {

String name() default "";

@AliasFor("path")
String[] value() default {};

@AliasFor("value")
String[] path() default {};

RequestMethod[] method() default {};

String[] params() default {};

String[] headers() default {};

String[] consumes() default {};

String[] produces() default {};

}

为什么就可以将请求 路由进来啊 实现代码在哪儿呢 什么原理啊???

  • 巴扎黑
  • 巴扎黑    2017-06-14 10:54:012楼

    如果不了解注解相关的知识,可以了解一下注解知识 1、文章1,2、文章2,这两篇讲解的还不错。之后可以百度一下spring mvc requestmapping 源码解读,网上的文章还是蛮多的。源码目前还没有读过,不过基本的原理应该也是通过反射获取到相应的配置,再根据配置进行请求路由。具体的是怎么根据反射获取相应配置的还是要去读一下源码。

    +0添加回复

  • 回复