【mysql】獲取某個表所有列名【mybatis】


 

方法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);

 

調用即可獲取!!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM