spring中有时候一个类上面标记不少注解。java
实际上Java注解能够进行继承(也就是把多个注解合并成1个)web
好比说SpringMVC的注解spring
@RestController
@RequestMapping("/person")复制代码
能够合并为一个markdown
@PathRestController("/user")复制代码
实现是:app
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 {};
}复制代码