查询所有表名

SELECT * from tab --查询数据库中所有的表名
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你使用 MyBatis Generator (MBG) 工具来生成查询所有表名的代码。以下是一个简单的示例: 1. 在 pom.xml 文件中添加以下依赖: ```xml <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.4.0</version> </dependency> ``` 2. 在 mybatis-generator.xml 文件中添加以下配置: ```xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> <generatorConfiguration> <context id="context1"> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/mydatabase" userId="myusername" password="mypassword"> </jdbcConnection> <javaModelGenerator targetPackage="com.example.model" targetProject="src/main/java"> </javaModelGenerator> <sqlMapGenerator targetPackage="com.example.mapper" targetProject="src/main/resources"> </sqlMapGenerator> <javaClientGenerator type="XMLMAPPER" targetPackage="com.example.mapper" targetProject="src/main/java"> </javaClientGenerator> <table tableName="%" domainObjectName="Table" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"> </table> </context> </generatorConfiguration> ``` 其中,`<jdbcConnection>` 标签中的参数需要根据你的数据库配置进行修改。 3. 运行 MBG 工具,生成代码: ```java public interface TableMapper { List<String> selectAllTableNames(); } ``` 你可以在 `selectAllTableNames()` 方法中执行查询所有表名SQL 语句,然后返回结果。例如: ```java public List<String> selectAllTableNames() { try (SqlSession sqlSession = sqlSessionFactory.openSession()) { return sqlSession.selectList("com.example.mapper.TableMapper.selectAllTableNames"); } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值