Java注解合並,注解繼承


莆田SEO: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 {}; } 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM