私は春に取り組んでおり、エンティティ Bean にカスタム注釈を追加しようとしました。私がやりたいのは、リフレクションを介して @ runtime というカスタム アノテーションを使用してフィールドにアクセスすることだけです。問題は、フィールドに複数の注釈がありますが、実行時にそれらのどれにもアクセスできないことです:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ChangeableField {
}
エンティティ:
public class Order {
@NotNull
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(pattern = "dd:MM:yyyy HH:mm")
@ChangeableField
private Date scheduledStart;
@NotNull
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(pattern = "dd:MM:yyyy HH:mm")
@ChangeableField
private Date scheduledEnd;
//...
}
どうすればいいのか全くわからない
Order.class.getField("scheduledStart").getAnnotation(ChangableField.class);
常に null を返します。(ところで、このフィールドで宣言されたすべての注釈は null です)
春と関係があるのかな。
助けていただければ幸いです。
前もって感謝します
編集
理由はわかりませんが、現在は正常に動作しています。
for (Field currentField : order.getClass().getDeclaredFields()) {
if (currentField.getAnnotation(ChangeableField.class) != null
&& map.containsKey(currentField.getName())) {
//..
ご協力いただきありがとうございます
ところで、この投稿のタイプミスでした..