「Spring MVC」独自アノテーションを作成する

環境
Eclipse 4.7.0
Java 1.8
Spring 4.3

1.独自アノテーションの定義
書式
public @interface アノテーション名{
String 列名();
}
使用例

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

  String ItemNameR();
  
  String ItemNameL();
  
  int pos() default 0;
}

2.アノテーションを利用します
書式
@CSVItem(ItemNameR = “値", ItemNameL = “値2", pos = 数値)
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
public class DocItemBean extends DocItem{
@CSVItem(ItemNameR = "アイテムの名前", ItemNameL = "TT_NUM", pos = 0)
protected String cftNum = "";
}
public class DocItemBean extends DocItem{ @CSVItem(ItemNameR = "アイテムの名前", ItemNameL = "TT_NUM", pos = 0) protected String cftNum = ""; }
public class DocItemBean extends DocItem{
      @CSVItem(ItemNameR = "アイテムの名前", ItemNameL = "TT_NUM", pos = 0)
      protected String cftNum = "";
}

 

SpringMVC

Posted by arkgame