Search in sources :

Example 1 with TableId

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);
}
Also used : TableId(com.baomidou.mybatisplus.annotation.TableId) Field(java.lang.reflect.Field) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with TableId

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());
}
Also used : TableId(com.baomidou.mybatisplus.annotation.TableId) TableId(com.baomidou.mybatisplus.annotation.TableId) TableField(com.baomidou.mybatisplus.annotation.TableField) Annotation(java.lang.annotation.Annotation)

Example 3 with TableId

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;
}
Also used : TableId(com.baomidou.mybatisplus.annotation.TableId) Field(java.lang.reflect.Field) TableField(com.baomidou.mybatisplus.annotation.TableField) TableField(com.baomidou.mybatisplus.annotation.TableField)

Example 4 with TableId

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);
}
Also used : TableId(com.baomidou.mybatisplus.annotation.TableId) Field(java.lang.reflect.Field) TableField(com.baomidou.mybatisplus.annotation.TableField) TableField(com.baomidou.mybatisplus.annotation.TableField)

Example 5 with TableId

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);
}
Also used : TableId(com.baomidou.mybatisplus.annotation.TableId) Field(java.lang.reflect.Field) TableField(com.baomidou.mybatisplus.annotation.TableField) TableField(com.baomidou.mybatisplus.annotation.TableField)

Aggregations

TableId (com.baomidou.mybatisplus.annotation.TableId)6 TableField (com.baomidou.mybatisplus.annotation.TableField)5 Field (java.lang.reflect.Field)5 Annotation (java.lang.annotation.Annotation)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1