提交
This commit is contained in:
parent
0b8ab8bff7
commit
23f189a7d6
@ -1,6 +1,10 @@
|
|||||||
package com.zhgd.xmgl.util;
|
package com.zhgd.xmgl.util;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.baomidou.mybatisplus.extension.api.R;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.apache.poi.ss.formula.functions.T;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.util.ReflectionUtils;
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
@ -8,6 +12,7 @@ import java.beans.Introspector;
|
|||||||
import java.lang.invoke.SerializedLambda;
|
import java.lang.invoke.SerializedLambda;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -17,7 +22,10 @@ import java.util.stream.Collectors;
|
|||||||
/**
|
/**
|
||||||
* 方法引用获取属性名工具类
|
* 方法引用获取属性名工具类
|
||||||
*/
|
*/
|
||||||
|
@Data
|
||||||
public class ReflectionUtil {
|
public class ReflectionUtil {
|
||||||
|
private String alias;
|
||||||
|
private List<SerializableFunction<T, R>> functions;
|
||||||
|
|
||||||
private static Map<SerializableFunction<?, ?>, Field> cache = new ConcurrentHashMap<>();
|
private static Map<SerializableFunction<?, ?>, Field> cache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@ -25,6 +33,20 @@ public class ReflectionUtil {
|
|||||||
return Arrays.stream(functions).map(ReflectionUtil::getFieldName).collect(Collectors.toList());
|
return Arrays.stream(functions).map(ReflectionUtil::getFieldName).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T, R> List<String> getFieldNameListWithAlias(List<ReflectionUtil> list) {
|
||||||
|
if (CollectionUtils.isEmpty(list)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ArrayList<String> l = new ArrayList<>();
|
||||||
|
for (ReflectionUtil reflectionUtil : list) {
|
||||||
|
for (SerializableFunction<org.apache.poi.ss.formula.functions.T, com.baomidou.mybatisplus.extension.api.R> function : reflectionUtil.getFunctions()) {
|
||||||
|
String fieldName = getFieldName(function);
|
||||||
|
l.add(reflectionUtil.getAlias() + "." + fieldName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
public static <T, R> String getFieldNameToUlc(SerializableFunction<T, R> function) {
|
public static <T, R> String getFieldNameToUlc(SerializableFunction<T, R> function) {
|
||||||
return StrUtil.toUnderlineCase(getFieldName(function));
|
return StrUtil.toUnderlineCase(getFieldName(function));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user