自定义注解
前提:发现只是会用,不知道具体怎么回事,很苦恼。
特在此进行简单的分析
注解
注解:是附加到代码中的一些元信息,这些元信息是在代码运行,编译时有效,且这些
注解并不影响我们原有的代码逻辑,只是起到了说明,配置的作用
自定义注解
元注解:注解中的注解
eg:
1.@Target 修饰的对象范围
2.@Retention 保留的时间长短
3.@Documented 标记注解,公共API 没有成员
4.@Inherited 标记注解,@Inherited阐述了某个被标注的类型 是被继承的
注解的使用范围:
@Target说明了Annotation所修饰的对象范围
1.CONSTRUCTOR:用于描述构造器
2.FIELD:用于描述域(属性)(常用)
3.LOCAL_VARIABLE:用于描述局部变量
4.METHOD:用于描述方法(常用、get方法,这个时候Spring2.3)
5.PACKAGE:用于描述包
6.PATAMETER:用于描述参数
7.TYPE:用于描述类、接口(包括注解类型) 或enum声明:
@TranSient这个是原有的注解
@Target({METHOD})
@Retention(RUNTIME)
public @interface Transient {
/**
* Returns whether or not the {@code Introspector} should
* construct artifacts for the annotated method.
* @return whether or not the {@code Introspector} should
* construct artifacts for the annotated method
*/
boolean value() default true;
}
@TranSient
@Target(Element.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Transient{
String value() default "";//注解的属性
}
1:@TranSient 自定义注解,如果作用域域(属性)上面,则代表该属性
不能被持久化序列
2:如果使用了该自定义注解,则代表该属性并非数据库的映射字段,ORM框架
映射的时候,会自动忽略该属性
3:起到了聚合VO的作用
4:Serializale提供了持久化实例的安全机制,如果使用了该注解字段
则该字段不能被实例化或者序列化
如若有不对的地方,请指出 不胜感激