Mybatis如何运行sql“ desc table”

时间:2018-07-08 13:23:49

标签: java mysql mybatis spring-mybatis

我对如何运行sql“ desc table”以获取表字段信息有疑问。

我尝试运行这些代码以获取表字段信息,但出现语法错误。

@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);}

有人可以告诉我如何使用mybaits获取表字段信息吗?

1 个答案:

答案 0 :(得分:1)

更改

try{  

    $sql =  "SELECT * FROM objects WHERE 1=1";
    $result = $mysql->get_results($sql);



  $json= '';
  if (count($result) > 0 ) {
    $json = array(
      'result' =>'ok',      
      'db' => $result,
    ); 
  } 
  else {
    $json = array(
      'result' =>'fail',
    );
  }

  echo json_encode($json);
  exit;
} 
catch(Exception $e) {
  echo 'Caught exception: ', $e->getMessage();
}

desc #{tableName}
     ^