java自定义注解

[复制链接]
发表于 2025-1-14 10:17:38 | 显示全部楼层 |阅读模式

定义

@Target({ElementType.TYPE, ElementType.METHOD,ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface NewSOFieldLength {

     String value();
}
@NewSOFieldName("enablestate")
    private String enablestate;
Field[] fields = t.getClass().getFields();
         
                if (fields.length > 0) {
                    for (Field field : fields
                    ) {
                        NewSOFieldName annoName = field.getAnnotation(NewSOFieldName.class);
                        field.setAccessible(true);
//属性值
                        String fieldVal = field.get(t) == null ? null : field.get(t).toString();
//NewSOFieldName 注解的value值
                        String name = annoName.value();
                       
                    }
                }

GMT+8, 2025-9-8 02:45 , Processed in 0.095957 second(s), 35 queries Archiver|手机版|小黑屋|Attic ( 京ICP备2020048627号 )

快速回复 返回顶部 返回列表