com.baomidou.mybatisplus.core.metadata.TableFieldInfo Java Examples
The following examples show how to use
com.baomidou.mybatisplus.core.metadata.TableFieldInfo.
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: 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 #2
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; }
Example #3
Source File: UpdateBatchById.java From summerframework with Apache License 2.0 | 5 votes |
protected String convertIfTag(SqlCommandType sqlCommandType, TableFieldInfo fieldInfo, String prefix, boolean colse) { /* 前缀处理 */ String property = fieldInfo.getProperty(); if (null != prefix) { property = prefix + property; } /* 判断策略 */ if (sqlCommandType == SqlCommandType.INSERT && fieldInfo.getFieldStrategy() == FieldStrategy.DEFAULT) { return ""; } if (fieldInfo.getFieldStrategy() == FieldStrategy.IGNORED) { return ""; } else if (fieldInfo.getFieldStrategy() == FieldStrategy.NOT_EMPTY) { if (colse) { return "</if>"; } else { return String.format("\n\t<if test=\"%s!=null and %s!=''\">", property, property); } } else { // FieldStrategy.NOT_NULL if (colse) { return "</if>"; } else { return String.format("\n\t<if test=\"%s!=null\">", property); } } }
Example #4
Source File: UpdateBatchById.java From summerframework with Apache License 2.0 | 4 votes |
protected String convertIfTag(TableFieldInfo fieldInfo, String prefix, boolean colse) { return convertIfTag(SqlCommandType.UNKNOWN, fieldInfo, prefix, colse); }
Example #5
Source File: UpdateBatchById.java From summerframework with Apache License 2.0 | 4 votes |
protected String convertIfTag(TableFieldInfo fieldInfo, boolean colse) { return convertIfTag(fieldInfo, null, colse); }
Example #6
Source File: SqlInjectorUtil.java From albedo with GNU Lesser General Public License v3.0 | 4 votes |
public static String sqlSelectColumns(TableInfo table, boolean entityWrapper, String columnPrefix, String selectProfix) { StringBuilder columns = new StringBuilder(); if (null != table.getResultMap()) { if (entityWrapper) { columns.append("<choose><when test=\"ew != null and ew.sqlSelect != null\">${ew.sqlSelect}</when><otherwise>"); } columns.append("*"); if (entityWrapper) { columns.append("</otherwise></choose>"); } } else { if (entityWrapper) { columns.append("<choose><when test=\"ew != null and ew.sqlSelect != null\">${ew.sqlSelect}</when><otherwise>"); } List<TableFieldInfo> fieldList = table.getFieldList(); int size = 0; if (null != fieldList) { size = fieldList.size(); } if (StringUtils.isNotEmpty(table.getKeyProperty())) { if (StringUtil.isNotEmpty(columnPrefix)) { columns.append('`').append(columnPrefix).append("`."); } String keyProperty = table.getKeyProperty(); if (StringUtil.isNotEmpty(selectProfix)) { keyProperty = selectProfix + StringUtil.DOT + keyProperty; } columns.append(table.getKeyColumn()).append(" AS ").append(sqlWordConvert(keyProperty)); if (size >= 1) { columns.append(","); } } if (size >= 1) { int i = 0; for (Iterator iterator = fieldList.iterator(); iterator.hasNext(); ++i) { TableFieldInfo fieldInfo = (TableFieldInfo) iterator.next(); String property = fieldInfo.getProperty(); if (StringUtil.isNotEmpty(selectProfix)) { property = selectProfix + StringUtil.DOT + property; } String wordConvert = sqlWordConvert(property); if (StringUtil.isNotEmpty(columnPrefix)) { columns.append('`').append(columnPrefix).append("`."); } columns.append(fieldInfo.getColumn()); columns.append(" AS ").append(wordConvert); if (i + 1 < size) { columns.append(","); } } } if (entityWrapper) { columns.append("</otherwise></choose>"); } } return columns.toString(); }