OnTheRoad
OnTheRoad

Reputation: 613

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?

Upvotes: 0

Views: 991

Answers (1)

flyingfox
flyingfox

Reputation: 13506

Change

desc #{tableName}
     ^

to

desc ${tableName}
     ^

Upvotes: 1

Related Questions