• MyBatis 获取数据库所有表名


    MyBatis 获取数据库所有表名
    添加链接描述

        (value = "/SELECT_table_name_list")
        public Object SELECT_table_name_list( QuestionPageRequestVM model) {
            List<Map<String, String>> lamperouge = commonRepository.SELECT_table_name_list("lamperouge", null);
           logger.info("lamperouge {}",lamperouge);
               return RestResponse.ok(lamperouge);
    
        }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    package com.mindskip.xzs.repository;//package com.dao;
    
    import org.apache.ibatis.annotations.Mapper;
    import org.apache.ibatis.annotations.Param;
    
    import java.util.List;
    import java.util.Map;
    
    @Mapper
    public interface CommonRepository {
    
        /**
         * 获取当前数据库表名
         *
         * @param tableNameList 表名列表
         * @return
         */
        List<String> getTableNameList(@Param("tableNameList") List<String> tableNameList);
        List<Map<String,String>> SELECT_table_name_list(@Param("table_schema") String  table_schema ,
                @Param("table_type") String table_type);
        List<Map<String,String>> select_information_schema_columns();
    
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <!--<mapper namespace="com.dao.CommonRepository">-->
    <mapper namespace="com.mindskip.xzs.repository.CommonRepository">
    
        <select id="getTableNameList" resultType="java.lang.String">
            select table_name from information_schema.tables where TABLE_SCHEMA=(select database())
            <if test="tableNameList !=null and tableNameList.size() > 0">
                and table_name in
                <foreach collection="tableNameList" item="item" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
        </select>
    
        <select id="SELECT_table_name_list" resultType="Map">
           SELECT
    
    table_name
    
    FROM
    
    information_schema.tables
    
    WHERE table_schema = #{table_schema}
        <if test="table_type !=null">
            AND table_type = #{table_type}
        </if>
    
        </select>
    
    
        <select id="select_information_schema_columns" resultType="Map">
           select * from information_schema.columns
        where table_schema= ? and table_name = ?
        </select>
    
    
    
    
    </mapper>
    
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44

    post
    http://localhost:8003/api/all/SELECT_table_name_list

    : lamperouge [{table_name=t_chapter}, {table_name=t_exam_paper}, {table_name=t_exam_paper_answer}, {table_name=t_exam_paper_question_customer_answer}, {table_name=t_message}, {table_name=t_message_user}, {table_name=t_question}, {table_name=t_question_2}, {table_name=t_subject}, {table_name=t_task_exam}, {table_name=t_task_exam_customer_answer}, {table_name=t_text_content}, {table_name=t_user}, {table_name=t_user_event_log}, {table_name=t_user_token}, {table_name=tenant}, {table_name=tenant_exam_paper}]
    2022-11-04 12:54:26.014 INFO 26320 — [nio-8003-exec-3] c.mindskip.xzs.utility.ControllerAspect : 方法执行完毕, 共用时:94毫秒

    {
    “code”: 1,
    “message”: “成功”,
    “response”: [
    {
    “table_name”: “t_chapter”
    },
    {
    “table_name”: “t_exam_paper”
    },
    {
    “table_name”: “t_exam_paper_answer”
    },
    {
    “table_name”: “t_exam_paper_question_customer_answer”
    },
    {
    “table_name”: “t_message”
    },
    {
    “table_name”: “t_message_user”
    },
    {
    “table_name”: “t_question”
    },
    {
    “table_name”: “t_question_2”
    },
    {
    “table_name”: “t_subject”
    },
    {
    “table_name”: “t_task_exam”
    },
    {
    “table_name”: “t_task_exam_customer_answer”
    },
    {
    “table_name”: “t_text_content”
    },
    {
    “table_name”: “t_user”
    },
    {
    “table_name”: “t_user_event_log”
    },
    {
    “table_name”: “t_user_token”
    },
    {
    “table_name”: “tenant”
    },
    {
    “table_name”: “tenant_exam_paper”
    }
    ]
    }

  • 相关阅读:
    Ubuntu上安装部署k8s集群
    Kotlin文件和类为什么不是一对一关系
    抖音小店最新入驻费用,2023具体费用分析!
    Python:实现iterative merge sort迭代归并排序算法(附完整源码)
    拼多多电商API接口详情
    vue从0到1搭建项目
    DSPE-PEG-FITC Fluorescein-PEG-DSPE 磷脂-聚乙二醇-荧光素可提高溶解度
    Docker安装Nginx(各种错误版)
    BAT034:批处理打开电脑常用功能面板
    jmeter-常用的一些java代码
  • 原文地址:https://blog.csdn.net/jonathan_joestar/article/details/127686767