package com.lovecoding.day24.anno01;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.stream.Stream;

public class Test01Annocation {
    public static void main(String[] args) {

        //Person.class
        Class<Person> personClass = Person.class;

        //获取注解
        Table annotation = personClass.getAnnotation(Table.class);

        String tableName = annotation.value();

        Field[] declaredFields = personClass.getDeclaredFields();
        //字段
        String[] cloumn = new String[declaredFields.length];

        //遍历
        Stream<Field> stream = Arrays.stream(declaredFields);

        for (int i = 0; i < declaredFields.length; i++) {
            declaredFields[i].setAccessible(true);
            Column eAnnotation = declaredFields[i].getAnnotation(Column.class);
            //获取字段
            cloumn[i] = eAnnotation.filed();
        }

        StringBuffer sb = new StringBuffer();

        sb.append( " select ");

        for (String s : cloumn) {
            sb.append(s).append(", ");
        }

        sb.append(" from ");
        sb.append(tableName);

        System.out.println(sb.toString());

        //select username age from person

    }
}
