「Spring」カスタムアノテーションを使うサンプル

構文
public @interface アノテーション名
使用例
1.アノテーションの定義

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Documented
public @interface ProItem {
String ProName();
int price() default 0;
}
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) @Documented public @interface ProItem { String ProName(); int price() default 0; }
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Documented
public @interface ProItem {
  
   String ProName();
   
   int price() default 0;
}

2.アノテーションを利用

@ProItem(ProName ="sampleAA", price =30)
protected String proType = “";

@ProItem(ProName ="sampleAA", price =0)
protected String proCd = “";

SpringMVC

Posted by arkgame