首页 > 编程知识 正文

java获取注解标注的方法,java调用数据库

时间:2023-05-06 10:14:23 阅读:134518 作者:4811

评论

注释是程序通过反射机制检索指定程序元素的Annotion对象的接口。 从此对象获取注释中的元数据。

元数据

mysql有元数据的概念,是对数据数据的描述

例如,mysql元数据可以获取数据库服务器的当前状态和服务器版本号。

元注释

对其他评论负责

板栗

@ retention (retetionpolicy.runtime ) )。

@target(elementtype.type ) )。

公共@ interface my annotation {

公共字符串名称(;

公共字符串值(;

}

解释; 在interface前面加上@表示这是一个注释,可以在其他地方使用

再定义两个指示。 其中,@Retetion表示注释将保留到正在运行,且不会在编译时删除

@Target表示只能在类和接口中使用

@target(elementtype.field ) )。

@ retention (retention policy.runtime ) )。

@Documented

public @interface Column{

//这里默认代表是默认代表,fieldName是默认内容

公共字符串名称(default ' field name );

公共字符串集函数() default 'getField ';

公共字符串获取函数() default 'getField ';

公共布尔默认值()默认值;

}

@Documented在java生成文档时使用

@inherited

注释的标记类型是继承的,如果class使用了使用@inherited限定的类型,则class是class的子类。

@Inherited

公共@ interface greeting {

公共事件字体颜色{ bule,RED,GREEN};

字符串名称(;

}

自定义注释

@target(elementtype.field ) )。

@ retention (retention policy.runtime ) )。

@Documented

公共@ interface fruit name {

String value () default ' );

}

@target(elementtype.field ) )。

@ retention (retention policy.runtime ) )。

@Documented

public @interface FruitColor{

public enum Color{BULE,RED,GREEN};

Color fruitColor () default Color.GREEN;

}

公共类应用程序{

//将默认值设置为苹果

@fruitname(apple );

私有字符串应用程序名称;

//将默认fruitColor默认值设置为Color.RED

@ fruit color (fruit color=color.red ) )

私有字符串应用程序颜色;

}

www.iming.info

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。