Java Code Examples for com.baomidou.mybatisplus.annotations.TableField#exist()

The following examples show how to use com.baomidou.mybatisplus.annotations.TableField#exist() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataRuleInitializer.java    From bird-java with MIT License 5 votes vote down vote up
/**
 * 扫描项目类所有class
 *
 * @param clazz class
 */
private Set<DataRuleInfo> collectRuleInfos(Class<?> clazz) {
    Set<DataRuleInfo> ruleInfos = new HashSet<>();

    TableName tableName = clazz.getAnnotation(TableName.class);
    Field[] fields = clazz.getDeclaredFields();
    for (Field field : fields) {
        TableField tableField = field.getAnnotation(TableField.class);
        if (tableField != null && !tableField.exist()) continue;

        DataRule dataRule = field.getAnnotation(DataRule.class);

        if (dataRule != null) {
            DataRuleInfo ruleInfo = new DataRuleInfo();
            ruleInfo.setAppName(applicationName);
            ruleInfo.setClassName(clazz.getName());
            ruleInfo.setFieldName(field.getName());
            ruleInfo.setDbFieldName(QueryDescriptor.getDbFieldName(field));
            ruleInfo.setName(dataRule.name());
            ruleInfo.setSourceStrategy(String.valueOf(dataRule.strategy().getKey()));
            ruleInfo.setTableName(StringUtils.wrapIfMissing(tableName.value(), "`"));
            if (RuleSourceStrategy.CHOICE.equals(dataRule.strategy())) {
                ruleInfo.setSourceUrl(dataRule.url());
            }
            if (RuleSourceStrategy.SYSTEM.equals(dataRule.strategy())) {
                ruleInfo.setSourceProvider(dataRule.provider().getName());
            }

            ruleInfos.add(ruleInfo);
        }
    }
    return ruleInfos;
}
 
Example 2
Source File: QueryDescriptor.java    From bird-java with MIT License 5 votes vote down vote up
public static QueryDescriptor parseClass(Class<?> tClass) {
    Map<String, String> fieldMap = new HashMap<>(16);

    if (tClass == null) return null;
    Class tempClass = tClass;
    StringBuilder sb = new StringBuilder();

    while (tempClass != null && !StringUtils.equals(tempClass.getName(), OBJECT_CLASS_NAME)) {
        Field[] tempFields = tempClass.getDeclaredFields();
        for (Field field : tempFields) {
            if(EXCLUDE_FIELD_NAMES.contains(field.getName()))continue;

            TableField tableField = field.getAnnotation(TableField.class);
            if (tableField != null && !tableField.exist()) continue;

            String fieldName = StringUtils.wrapIfMissing(field.getName(), '`');
            String dbFieldName = getDbFieldName(field);
            fieldMap.putIfAbsent(fieldName, dbFieldName);
        }

        tempClass = tempClass.getSuperclass();
    }

    for (Map.Entry<String, String> entry : fieldMap.entrySet()) {
        sb.append(entry.getValue());
        sb.append(" AS ");
        sb.append(entry.getKey());
        sb.append(",");
    }

    String select = StringUtils.stripEnd(sb.toString(), ",");

    String from = "";
    TableName tableName = tClass.getAnnotation(TableName.class);
    if (tableName != null) {
        from = tableName.value();
    }
    return new QueryDescriptor(select, from, fieldMap);
}
 
Example 3
Source File: CommonSaveProvider.java    From bird-java with MIT License 5 votes vote down vote up
/**
 * 获取字段名与值的映射关系
 *
 * @param param param
 * @return map
 */
private Map<String, String> getFieldValueMap(CommonSaveParam param) {
    Map<String, String> map = new LinkedHashMap<>();

    String tableName = formatName(param.getTableName());

    Field[] fields = param.gettClass().getDeclaredFields();
    for (Field field : fields) {
        if (EXCLUDE_FIELD_NAMES.contains(field.getName())) continue;

        TableField tableField = field.getAnnotation(TableField.class);
        if (tableField != null && !tableField.exist()) continue;
        String fieldName = tableField == null ? field.getName() : tableField.value();
        //处理适用于多表的DTO
        if (fieldName.contains(".")) {
            String[] arr = fieldName.split("\\.");
            if (!StringUtils.equals(formatName(arr[arr.length - 2]), tableName)) continue;

            fieldName = arr[arr.length - 1];
        }

        fieldName = formatName(fieldName);
        if (STATIC_FIELDS.contains(fieldName)) continue;

        String fieldValue = getFieldValue(param.getEntityDTO(), field);
        map.put(fieldName, fieldValue);
    }
    return map;
}