Search in sources :

Example 1 with SFunction

use of com.baomidou.mybatisplus.core.toolkit.support.SFunction in project video-spider by zc-libre.

the class FieldUtils method getFieldName.

/**
 * 获取字段名称
 *
 * @param func 列函数
 * @param <R>  泛型
 * @return 泛型
 */
public static <R> String getFieldName(R func) {
    if (!(func instanceof SFunction)) {
        throw new RuntimeException("not support this type of column");
    }
    try {
        // 通过获取对象方法,判断是否存在该方法
        Method method = func.getClass().getDeclaredMethod("writeReplace");
        method.setAccessible(Boolean.TRUE);
        // 利用jdk的SerializedLambda 解析方法引用
        SerializedLambda serializedLambda = (SerializedLambda) method.invoke(func);
        String getter = serializedLambda.getImplMethodName();
        return resolveFieldName(getter);
    } catch (ReflectiveOperationException e) {
        throw new RuntimeException(e);
    }
}
Also used : SFunction(com.baomidou.mybatisplus.core.toolkit.support.SFunction) Method(java.lang.reflect.Method) SerializedLambda(java.lang.invoke.SerializedLambda)

Aggregations

SFunction (com.baomidou.mybatisplus.core.toolkit.support.SFunction)1 SerializedLambda (java.lang.invoke.SerializedLambda)1 Method (java.lang.reflect.Method)1