Search code examples
javamysqlmybatisspring-mybatis

Mybatis how to run the sql "desc table"


I have a promble about how to run the sql "desc table" to get table fields info.

I am try run this those code to get table fields info, but got an syntax error.

@Mapper
public interface TableMapper {

/**
 * 获取指定表中字段的具体信息
 * @param tableName 表名
 * @return 所有字段的具体信息.
 */
@Select("desc #{tableName}")
@Results({
        @Result(property = "fieldName", column = "Field", javaType = String.class),
        @Result(property = "fieldType", column = "Type", javaType = String.class),
        @Result(property = "nullable", column = "Null", javaType = String.class),
        @Result(property = "key", column = "Key", javaType = String.class),
        @Result(property = "extra", column = "Extra", javaType = String.class)
})
Set<TableFieldInfo> findTableFieldsInfo(@Param(value = "tableName") String tableName);}

Can some one tell me how to get table fields info with mybaits?


Solution

  • Change

    desc #{tableName}
         ^
    

    to

    desc ${tableName}
         ^