将多个注解合并到一起,这样不用每次都要写若干个重复的注解。
例子
SpringMVC
中的注解
@RestController
@RequestMapping("/user")
可以合并成@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 {};
}
@AliasFor
这是Spring
提供的注解,用来为其它属性赋值。
比如
@AliasFor("path")
String[] value() default {};
就是把value的值也给path赋值。以此实现value和path的值保持一致。
网友评论