use of com.baomidou.mybatisplus.core.toolkit.support.SerializedLambda in project JBM by numen06.
the class EntityUtils method toFieldName.
// public static <T> String setDefault(T bean, boolean criteria, SFunction<T, ?> func) {
// if (criteria) {
// BeanUtil.getProperty(bean, toFieldName(func));
// }
//
// }
/**
* 转换方法引用为属性名
* @param func
* @return
*/
public static <T> String toFieldName(SFunction<T, ?> func) {
SerializedLambda lambda = LambdaUtils.resolve(func);
// 获取方法名
String methodName = lambda.getImplMethodName();
String prefix = null;
if (methodName.startsWith("get")) {
prefix = "get";
} else if (methodName.startsWith("set")) {
prefix = "set";
} else if (methodName.startsWith("is")) {
prefix = "is";
}
if (prefix == null) {
log.info("无效的getter方法: {}", methodName);
}
String field = StrUtil.subAfter(methodName, prefix, false);
return StrUtil.lowerFirst(field);
}
use of com.baomidou.mybatisplus.core.toolkit.support.SerializedLambda in project chao-cloud by chaojunzi.
the class FunctionUtil method getFieldName.
static <T, R> String getFieldName(SFunction<T, R> func) {
SerializedLambda lambda = LambdaUtils.resolve(func);
String methodName = lambda.getImplMethodName();
return StrUtil.getGeneralField(methodName);
}
use of com.baomidou.mybatisplus.core.toolkit.support.SerializedLambda in project chao-cloud by chaojunzi.
the class FunctionUtil method getColumn.
static <T, R> String getColumn(SFunction<T, R> func) {
SerializedLambda lambda = LambdaUtils.resolve(func);
String fieldName = StrUtil.getGeneralField(lambda.getImplMethodName());
Class<?> beanClass = lambda.getImplClass();
TableInfo info = buildTableInfo(beanClass);
Assert.notNull(info, "无效的数据实体 beanClass={}", beanClass.getName());
Map<String, String> propColumnMap = info.getFieldList().stream().collect(Collectors.toMap(TableFieldInfo::getProperty, TableFieldInfo::getColumn));
String column = propColumnMap.get(fieldName);
Assert.notBlank(column, "无效的列名映射 fieldName={}", fieldName);
return column;
}
use of com.baomidou.mybatisplus.core.toolkit.support.SerializedLambda in project chao-cloud by chaojunzi.
the class MybatisUtil method getColumn.
/**
* 根据实体获取列名
*
* @param func 表达式
* @return column
*/
static <T, R> String getColumn(SFunction<T, R> func) {
SerializedLambda lambda = SerializedLambda.resolve(func);
// 获取实体类型
Class<?> entityClass = lambda.getImplClass();
// 获取方法类型
String fieldName = StrUtil.getGeneralField(lambda.getImplMethodName());
// 获取属性
Field field = ReflectUtil.getField(entityClass, fieldName);
TableField tableField = AnnotationUtil.getAnnotation(field, TableField.class);
if (tableField != null) {
String column = tableField.value();
if (StrUtil.isNotBlank(column)) {
return column;
}
}
return StrUtil.toUnderlineCase(fieldName);
}
Aggregations