use of com.baomidou.mybatisplus.annotation.TableId in project diboot by dibo-software.
the class BeanUtilsTest method getField.
@Test
public void getField() {
Field field = BeanUtils.extractField(Dictionary.class, "id");
TableId id = field.getAnnotation(TableId.class);
Assert.assertTrue(id != null);
}
use of com.baomidou.mybatisplus.annotation.TableId 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.TableId 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.TableId 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);
}
use of com.baomidou.mybatisplus.annotation.TableId in project albedo by somowhere.
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