Java???annotation?÷???????????????
???????????? ???????[ 2013/6/21 13:33:50 ] ????????
????????
??????J2EE?У???????????????????????????XML???????????Hibernate????????У????????????ü???????????????????XML?????????????????????????annotation???÷????????????????????????????????????????????д????????????????????????????????
????????????
????Java???????????????????????????????????????????????
?????????????
????@Override????????????????帲????????е??????????????????????????????????????????????????????????????????????????????????з????????????
????@Deprecated?????????????????????????????????????????????????????????????
????@SuppressWarnings??????????????????????
????????????
????@Target??????????????????????
??????CONSTRUCTOR??????????????FIELD??????????METHOD????????????TYPE????????enum????
????@Retention???????????????????????????
??????SOURCE???????????????????CLASS???????class????????????VM????
????RUNTIME??VM?????????????????????????÷??????????????
????@Documented??????????????Javadoc?С?
????@Inherited???????????и???????
???????????
????????????????@interface???????????????????壬?????漲??????????????????????????????????????????????????????????????default??????????????????????????????????????null??????????????????????????????????????
?????????????
package whut.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
//??????????
@Target(ElementType.METHOD)//??????????????????????????????
@Retention(RetentionPolicy.RUNTIME)//??????????????????????
public @interface UseCase {
//???????????????????????????????????????????????id=5
public int id();
public String description() default "no description";
//????????????ò???????
public enum ParameterType { STRING?? SHORT?? INT?? BOOL?? LONG?? OBJECT };
// ????????????????????????????
public ParameterType type() default ParameterType.STRING;
}
??????????
??????????????????????????????????@?????????@UseCase??id=5???????????????У??????????????????????????и????????????????????а?????-????????????????????????????value?????????????????????????????????????????value??????????
?????????????е??
??????????????????????÷?apt???????????????
??????????????????壬????????????佨???????????????????
????????壺??????????????????????С?
package whut.annotationDB;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
//??????ε????
public @interface Constraints {
boolean primaryKey() default false;
boolean allowNull() default true;
boolean unique() default false;
}
////////////////////////////
package whut.annotationDB;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.TYPE)//??????enum
@Retention(RetentionPolicy.RUNTIME)
//????????????
public @interface DBTable {
public String name() default "";
}
///////////////////////////
package whut.annotationDB;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.FIELD)//??????enum
@Retention(RetentionPolicy.RUNTIME)
public @interface SQLInteger {
String name() default "";
//?????????????column???????????????????????
Constraints constraints() default @Constraints;
}
///////////////////////////////
package whut.annotationDB;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.FIELD)//??????enum
@Retention(RetentionPolicy.RUNTIME)
public @interface SQLString {
int value() default 0;
String name() default "";
//?????????????????
Constraints constraints() default @Constraints;
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11