java custom annotations
淡淡烟草味
淡淡烟草味 2017-06-14 10:52:01
0
2
924

For example, springmvc’s 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 {};

}

Why can requests be routed in? Where is the implementation code? What is the principle? ? ?

淡淡烟草味
淡淡烟草味

reply all(2)
巴扎黑

If you don’t know about annotation related knowledge, you can learn about annotation knowledge 1. Article 1, 2, and Article 2. These two articles explain it well. After that, you can Baidu to interpret the source code of spring mvc requestmapping. There are still quite a lot of articles on the Internet. I haven't read the source code yet, but the basic principle should be to obtain the corresponding configuration through reflection, and then route the request according to the configuration. Specifically, how to obtain the corresponding configuration based on reflection still requires reading the source code.

習慣沉默

/a/11...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template