Administrator
2018-10-30 7bf6a0582c7c62c90ee2ed8a88654f11d0479092
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package org.yeshi.utils.mybatis;
 
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
 
public class ColumnParseUtil {
 
    public static void parseColumn(Class<?> clz, String path) {
        Field[] fields = clz.getDeclaredFields();
        for (Field fd : fields) {
            Annotation[] as = fd.getAnnotations();
            for (Annotation a : as) {
                if (a instanceof Column) {
                    Column c = (Column) a;
                    System.out.println(c.name());
                    ColumnUtil.addColumnToMapper(path, c.name(), fd.getName(), getJDBCType(fd.getType().getName()));
                }
            }
        }
    }
 
    public static String getJDBCType(String type) {
        if (type.endsWith("java.lang.Long")) {
            return "BIGINT";
        } else if (type.endsWith("java.lang.Integer")) {
            return "INTEGER";
        } else if (type.endsWith("java.lang.String")) {
            return "VARCHAR";
        } else if (type.endsWith("java.lang.Boolean")) {
            return "BOOLEAN";
        } else if (type.endsWith("java.math.BigDecimal")) {
            return "DECIMAL";
        } else if (type.endsWith("java.util.Date")) {
            return "TIMESTAMP";
        }else
            return "VARCHAR";
    }
 
}