com.baomidou.mybatisplus.core.metadata.TableInfoHelper Java Examples
The following examples show how to use
com.baomidou.mybatisplus.core.metadata.TableInfoHelper.
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: SuperServiceImpl.java From microservices-platform with Apache License 2.0 | 6 votes |
@Override public boolean saveOrUpdateIdempotency(T entity, DistributedLock lock, String lockKey, Wrapper<T> countWrapper, String msg) throws Exception { if (null != entity) { Class<?> cls = entity.getClass(); TableInfo tableInfo = TableInfoHelper.getTableInfo(cls); if (null != tableInfo && StrUtil.isNotEmpty(tableInfo.getKeyProperty())) { Object idVal = ReflectionKit.getMethodValue(cls, entity, tableInfo.getKeyProperty()); if (StringUtils.checkValNull(idVal) || Objects.isNull(getById((Serializable) idVal))) { if (StrUtil.isEmpty(msg)) { msg = "已存在"; } return this.saveIdempotency(entity, lock, lockKey, countWrapper, msg); } else { return updateById(entity); } } else { throw ExceptionUtils.mpe("Error: Can not execute. Could not find @TableId."); } } return false; }
Example #2
Source File: LambdaColumn.java From spring-boot-plus with Apache License 2.0 | 6 votes |
/** * 从mybatisplus的TableInfo类中获取列名map信息 * * @param cls * @return */ private Map<String, String> getPropertyColumnMap(Class<?> cls) { TableInfo tableInfo = TableInfoHelper.getTableInfo(cls); List<TableFieldInfo> tableFieldInfos = tableInfo.getFieldList(); if (CollectionUtils.isEmpty(tableFieldInfos)) { return null; } Map<String, String> map = new ConcurrentHashMap<>(); String keyProperty = tableInfo.getKeyProperty(); String keyColumn = tableInfo.getKeyColumn(); map.put(keyProperty, keyColumn); for (TableFieldInfo tableFieldInfo : tableFieldInfos) { String column = tableFieldInfo.getColumn(); String property = tableFieldInfo.getProperty(); map.put(property, column); } return map; }
Example #3
Source File: SqlInjectorUtil.java From albedo with GNU Lesser General Public License v3.0 | 6 votes |
public static String parseSql(MapperBuilderAssistant builderAssistant, SqlCustomMethod sqlMethod, Class<?> modelClass, TableInfo tableInfo, String sqlWhereEntityWrapper) { String tableNameAlias = StringUtil.lowerCase(modelClass.getSimpleName()), tempNameAlias; TableInfo tableAlias; PropertyDescriptor[] ps = BeanUtil.getPropertyDescriptors(modelClass); StringBuffer sbSelectCoumns = new StringBuffer(SqlInjectorUtil.sqlSelectColumns(tableInfo, false, tableNameAlias, null)), sbLeftJoin = new StringBuffer(tableInfo.getTableName()).append(" `").append(tableNameAlias).append("`"); for (PropertyDescriptor p : ps) { ManyToOne annotation = ClassUtil.findAnnotation(modelClass, p.getName(), ManyToOne.class); if (annotation != null) { tableAlias = TableInfoHelper.initTableInfo(builderAssistant, p.getPropertyType()); sbSelectCoumns.append(",") .append(SqlInjectorUtil.sqlSelectColumns(tableAlias, false, p.getName(), p.getName())); sbLeftJoin.append(" LEFT JOIN ").append(tableAlias.getTableName()).append(" `").append(p.getName()) .append("` ON `").append(tableNameAlias).append("`.").append(annotation.name()) .append(" = `").append(p.getName()).append("`.").append(TreeEntity.F_SQL_ID); } } String sql = String.format(sqlMethod.getSql(), sbSelectCoumns.toString(), sbLeftJoin.toString(), sqlWhereEntityWrapper); return sql; }
Example #4
Source File: PropertyColumnUtil.java From spring-boot-plus with Apache License 2.0 | 5 votes |
/** * 根据实体class,从mybatisplus中获取对应Table的属性列名Map * * @param clazz * @return */ private static Map<String, String> getTableFieldMap(Class<?> clazz) { TableInfo tableInfo = TableInfoHelper.getTableInfo(clazz); if (tableInfo == null) { return null; } List<TableFieldInfo> tableFieldInfos = tableInfo.getFieldList(); if (CollectionUtils.isEmpty(tableFieldInfos)) { return null; } Map<String, String> cacheMap = tableFieldInfos.stream().collect(Collectors.toMap(TableFieldInfo::getProperty, TableFieldInfo::getColumn)); return cacheMap; }