use of com.baomidou.mybatisplus.annotation.TableField in project jeecg-boot by jeecgboot.
the class QueryGenerator method getTableFieldName.
/**
* 获取表字段名
* @param clazz
* @param name
* @return
*/
private static String getTableFieldName(Class<?> clazz, String name) {
try {
// 如果字段加注解了@TableField(exist = false),不走DB查询
Field field = null;
try {
field = clazz.getDeclaredField(name);
} catch (NoSuchFieldException e) {
// e.printStackTrace();
}
// 如果为空,则去父类查找字段
if (field == null) {
List<Field> allFields = getClassFields(clazz);
List<Field> searchFields = allFields.stream().filter(a -> a.getName().equals(name)).collect(Collectors.toList());
if (searchFields != null && searchFields.size() > 0) {
field = searchFields.get(0);
}
}
if (field != null) {
TableField tableField = field.getAnnotation(TableField.class);
if (tableField != null) {
if (tableField.exist() == false) {
// 如果设置了TableField false 这个字段不需要处理
return null;
} else {
String column = tableField.value();
// 如果设置了TableField value 这个字段是实体字段
if (!"".equals(column)) {
return column;
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return name;
}
use of com.baomidou.mybatisplus.annotation.TableField in project katoumegumi_all by 353259576.
the class FieldColumnRelationMapperFactory method createFieldColumnRelation.
public static FieldColumnRelation createFieldColumnRelation(Field field) {
Annotation[] annotations = field.getAnnotations();
boolean isId = false;
String columnName = null;
boolean getId = false;
boolean getColumn = false;
if (WsListUtils.isNotEmpty(annotations)) {
for (Annotation annotation : annotations) {
if (!getColumn && annotation instanceof Column) {
columnName = ((Column) annotation).name();
getColumn = true;
} else if (!getColumn && annotation instanceof TableField) {
columnName = ((TableField) annotation).value();
getColumn = true;
} else if (annotation instanceof TableId) {
isId = true;
columnName = ((TableId) annotation).value();
break;
} else if (!getId && annotation instanceof Id) {
isId = true;
getId = true;
}
}
}
if (WsStringUtils.isBlank(columnName)) {
columnName = getChangeColumnName(field.getName());
}
return new FieldColumnRelation(isId, field.getName(), field, columnName, field.getType());
}
use of com.baomidou.mybatisplus.annotation.TableField in project kykms by mahonelau.
the class QueryGenerator method getTableFieldName.
/**
* 获取表字段名
* @param clazz
* @param name
* @return
*/
private static String getTableFieldName(Class<?> clazz, String name) {
try {
// 如果字段加注解了@TableField(exist = false),不走DB查询
Field field = null;
try {
field = clazz.getDeclaredField(name);
} catch (NoSuchFieldException e) {
// e.printStackTrace();
}
// 如果为空,则去父类查找字段
if (field == null) {
List<Field> allFields = getClassFields(clazz);
List<Field> searchFields = allFields.stream().filter(a -> a.getName().equals(name)).collect(Collectors.toList());
if (searchFields != null && searchFields.size() > 0) {
field = searchFields.get(0);
}
}
if (field != null) {
TableField tableField = field.getAnnotation(TableField.class);
if (tableField != null) {
if (tableField.exist() == false) {
// 如果设置了TableField false 这个字段不需要处理
return null;
} else {
String column = tableField.value();
// 如果设置了TableField value 这个字段是实体字段
if (!"".equals(column)) {
return column;
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return name;
}
use of com.baomidou.mybatisplus.annotation.TableField in project muses by acgist.
the class FilterQuery method column.
/**
* 通过MyBatis注解获取数据库列名
*
* @param <T> 类型
*
* @param entity entity
* @param name Java字段名称
*
* @return 数据库列名
*/
private static final <T> String column(Class<T> entity, final String name) {
final Field field = FieldUtils.findField(entity, name);
if (field == null) {
return name;
}
final TableField tableField = field.getAnnotation(TableField.class);
if (tableField != null && StringUtils.isNotEmpty(tableField.value())) {
return tableField.value();
}
final TableId tableId = field.getAnnotation(TableId.class);
if (tableId != null && StringUtils.isNotEmpty(tableId.value())) {
return tableId.value();
}
return name;
}
use of com.baomidou.mybatisplus.annotation.TableField in project lamp-util by zuihou.
the class Wraps method getDbField.
/**
* 根据 bean字段 反射出 数据库字段
*
* @param beanField 字段
* @param clazz 类型
* @return 数据库字段名
*/
public static String getDbField(String beanField, Class<?> clazz) {
ArgumentAssert.notNull(clazz, "实体类不能为空");
ArgumentAssert.notEmpty(beanField, "字段名不能为空");
Field field = ReflectUtil.getField(clazz, beanField);
ArgumentAssert.notNull(field, "在类:{}中找不到属性:{}", clazz.getSimpleName(), beanField);
TableField tf = field.getAnnotation(TableField.class);
if (tf != null && StrUtil.isNotEmpty(tf.value())) {
return tf.value();
}
TableId ti = field.getAnnotation(TableId.class);
if (ti != null && StrUtil.isNotEmpty(ti.value())) {
return ti.value();
}
throw BizException.wrap("{}.{} 未标记 @TableField 或 @TableId", clazz.getSimpleName(), beanField);
}
Aggregations