【mysql】获取某个表所有列名【mybatis】

人盡茶涼 提交于 2020-10-14 05:06:02

 

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

 

调用即可获取!!

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!