国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

JSP 中Spring組合注解與元注解實例詳解

2020-07-27 21:24:20
字體:
來源:轉載
供稿:網(wǎng)友

JSP 中Spring組合注解與元注解實例詳解

摘要: 注解(Annotation),也叫元數(shù)據(jù)。一種代碼級別的說明。它與類、接口、枚舉是在同一個層次。它可以聲明在包、類、字段、方法、局部變量、方法參數(shù)等的前面,用來對這些元素進行說明

1. 可以注解到別的注解上的注解稱為元注解,被注解的注解稱為組合注解,通過組合注解可以很好的簡化好多重復性的注解操作

2. 示例組合注解

import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.Configuration;import java.lang.annotation.*;@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)@Documented@Configuration@ComponentScanpublic @interface GroupAnnotation {  String[] value() default {};}

代碼解釋:組合@Configuration 與 @ComponentScan 元注解,并覆蓋value參數(shù)

3. 編寫普通Bean

@Servicepublic class DemoService {  public void sys() {   System.out.println("組合注解示例");  }}

4. 使用組合注解的配置類

@GroupAnnotation("com.xuanwu.annotation")public class DemoConfig {}

5. 運行

public class Main {  public static void main(String[] args) {   AnnotationConfigApplicationContext context = new      AnnotationConfigApplicationContext(DemoConfig.class);   DemoService demoService = context.getBean(DemoService.class);   demoService.sys();  }}

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 铁力市| 彰化市| 杭锦后旗| 衢州市| 乾安县| 闽侯县| 翁源县| 乃东县| 乐亭县| 松溪县| 奈曼旗| 金门县| 黔西县| 双牌县| 石家庄市| 赤峰市| 毕节市| 五大连池市| 阳信县| 台安县| 都匀市| 娱乐| 嘉定区| 南投市| 盐津县| 江门市| 商城县| 吴忠市| 罗江县| 兖州市| 桂林市| 兴宁市| 弋阳县| 富阳市| 神木县| 乐安县| 铁岭县| 乌兰县| 瑞丽市| 东阿县| 平顺县|