@retention记录
package com.example.demo;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Field;
@Retention(RetentionPolicy.RUNTIME)
@interface one{
String name();
int length() default 0;
}
@Retention(RetentionPolicy.RUNTIME)
@interface two{
String value();
}
@Table("tb_student")
class retentionDemo{
@Property(name="id")
private Integer id;
}
public class RetentionTest {
public static void main(String[] args) throws ClassNotFoundException {
Class<?> forName = Class.forName("");
Field[] declaredFields = forName.getDeclaredFields();
StringBuffer stf = new StringBuffer();
stf.append(" select ");
for (int i = 0; i < declaredFields.length; i++) {
Field field = declaredFields[i];
Property property = field.getAnnotation(Property.class);
stf.append(property.name());
if (i<declaredFields.length - 1 ) {
stf.append(",");
}
}
Table declaredAnnotation = forName.getDeclaredAnnotation(Table.class);
stf.append(" from "+declaredAnnotation.value());
System.out.println(stf);
}
}
}