package cn.superred.support.utils;
import cn.hutool.db.meta.Column;
import com.alibaba.fastjson.annotation.JSONField;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.javassist.bytecode.stackmap.BasicBlock;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Map;
public class AnnotationUtils {
/**
* 查看注解属性
* @param t
* @param name
* @return
* @throws NoSuchFieldException
*/
public static Object getJSONFieldProp(Object t, String name) throws NoSuchFieldException {
Field field = t.getClass().getDeclaredField(name);
JSONField annotation = field.getAnnotation(JSONField.class);
String strName = annotation.name();
return strName;
}
/**
* 修改注解属性
* @param t
* @param value
* @return
* @throws NoSuchFieldException
* @throws IllegalAccessException
*/
public static void setJSONFieldProp(Object t, String name, Object value) throws NoSuchFieldException, IllegalAccessException {
Field field = t.getClass().getDeclaredField(name);
JSONField annotation = field.getAnnotation(JSONField.class);
InvocationHandler invocationHandler = Proxy.getInvocationHandler(annotation);
Field memberValues = invocationHandler.getClass().getDeclaredField("memberValues");
memberValues.setAccessible(true);
Map map = (Map) memberValues.get(invocationHandler);
map.put("name",value);
}
}