「Spring」独自アノテーション(@interface)のメソッド作成方法

2021年10月11日

1.独自アノテーションの作成
書式
public @interface アノテーション名{//処理コード}
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@Retention(RetentionPolicy.RUNTIME)
@Target( { ElementType.TYPE,ElementType.FIELD})
public @interface CftAnnotaion {
//メソッドkey作成
String key() default "";
//メソッドdelInfo作成
boolean delInfo() default true;
}
@Retention(RetentionPolicy.RUNTIME) @Target( { ElementType.TYPE,ElementType.FIELD}) public @interface CftAnnotaion { //メソッドkey作成 String key() default ""; //メソッドdelInfo作成 boolean delInfo() default true; }
@Retention(RetentionPolicy.RUNTIME)
@Target( { ElementType.TYPE,ElementType.FIELD})
public @interface CftAnnotaion {

  //メソッドkey作成
   String key() default "";
   
   //メソッドdelInfo作成
   boolean delInfo() default true;
   
 }

2.使い方
書式
@アノテーション名(メソッド1="xxx",メソッド2="xxx")
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@CftAnnotaion(key ="userDto",delInfo = false)
public UserDto userDto;
@CftAnnotaion(key ="userDto",delInfo = false) public UserDto userDto;
@CftAnnotaion(key ="userDto",delInfo = false)
public UserDto userDto;

 

SpringMVC

Posted by arkgame