spring中有時候一個類上面標記很多注解。
實際上Java注解可以進行繼承(也就是把多個注解合並成1個)
比如說SpringMVC的注解
@RestController
@RequestMapping("/person")
可以合並為一個
@PathRestController("/user")
實現是:
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;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@RestController
@RequestMapping
public @interface PathRestController {
@AliasFor("path")
String[] value() default {};
@AliasFor("value")
String[] path() default {};
}