方法1:[僅指定表名]java
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中如何調用?====================mybatis
mapper.xml:app
<select id="findFieldByTableName" parameterType="java.lang.String" resultType="java.lang.String"> SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE table_name = #{tableName}; </select>
mapper.javaspa
List<String> findFieldByTableName(@Param("tableName") String tableName);
調用便可獲取!!code