Java Code Examples for tk.mybatis.mapper.entity.EntityTable#getBaseSelect()

The following examples show how to use tk.mybatis.mapper.entity.EntityTable#getBaseSelect() . 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: EntityHelper.java    From tk-mybatis with MIT License 6 votes vote down vote up
/**
 * 获取查询的Select
 *
 * @param entityClass
 * @return
 */
public static String getSelectColumns(Class<?> entityClass) {
    EntityTable entityTable = getEntityTable(entityClass);
    if (entityTable.getBaseSelect() != null) {
        return entityTable.getBaseSelect();
    }
    Set<EntityColumn> columnList = getColumns(entityClass);
    StringBuilder selectBuilder = new StringBuilder();
    boolean skipAlias = Map.class.isAssignableFrom(entityClass);
    for (EntityColumn entityColumn : columnList) {
        selectBuilder.append(entityColumn.getColumn());
        if (!skipAlias && !entityColumn.getColumn().equalsIgnoreCase(entityColumn.getProperty())) {
            //不等的时候分几种情况,例如`DESC`
            if (entityColumn.getColumn().substring(1, entityColumn.getColumn().length() - 1).equalsIgnoreCase(entityColumn.getProperty())) {
                selectBuilder.append(",");
            } else {
                selectBuilder.append(" AS ").append(entityColumn.getProperty()).append(",");
            }
        } else {
            selectBuilder.append(",");
        }
    }
    entityTable.setBaseSelect(selectBuilder.substring(0, selectBuilder.length() - 1));
    return entityTable.getBaseSelect();
}
 
Example 2
Source File: EntityHelper.java    From Mapper with MIT License 6 votes vote down vote up
/**
 * 获取查询的Select
 *
 * @param entityClass
 * @return
 */
public static String getSelectColumns(Class<?> entityClass) {
    EntityTable entityTable = getEntityTable(entityClass);
    if (entityTable.getBaseSelect() != null) {
        return entityTable.getBaseSelect();
    }
    Set<EntityColumn> columnList = getColumns(entityClass);
    StringBuilder selectBuilder = new StringBuilder();
    boolean skipAlias = Map.class.isAssignableFrom(entityClass);
    for (EntityColumn entityColumn : columnList) {
        selectBuilder.append(entityColumn.getColumn());
        if (!skipAlias && !entityColumn.getColumn().equalsIgnoreCase(entityColumn.getProperty())) {
            //不等的时候分几种情况,例如`DESC`
            if (entityColumn.getColumn().substring(1, entityColumn.getColumn().length() - 1).equalsIgnoreCase(entityColumn.getProperty())) {
                selectBuilder.append(",");
            } else {
                selectBuilder.append(" AS ").append(entityColumn.getProperty()).append(",");
            }
        } else {
            selectBuilder.append(",");
        }
    }
    entityTable.setBaseSelect(selectBuilder.substring(0, selectBuilder.length() - 1));
    return entityTable.getBaseSelect();
}