【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