方法1:[仅指定表名]

select COLUMN_NAME from information_schema.COLUMNS where table_name = 'your-table-name';

 

方法2:[指定表名+数据库名]

select COLUMN_NAME from information_schema.COLUMNS where table_name = 'your-table-name' and table_schema = 'your-DB-name';

 

 

========================那在mybatis中如何调用?====================

mapper.xml:

 <select id="findFieldByTableName" parameterType="java.lang.String" resultType="java.lang.String">
        SELECT
            COLUMN_NAME
        FROM
            information_schema.COLUMNS
        WHERE
            table_name = #{tableName};
    </select>

 

 

mapper.java

List<String> findFieldByTableName(@Param("tableName") String tableName);

 

调用即可获取!!

 

相关文章:

  • 2021-10-25
  • 2022-02-04
  • 2022-12-23
  • 2022-12-23
  • 2021-09-14
  • 2021-12-09
  • 2021-07-27
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-23
  • 2021-12-26
  • 2022-01-30
  • 2021-12-24
  • 2022-12-23
  • 2021-11-07
相关资源
相似解决方案