自动生成代码数据库查询语句

 

import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface GeneratorMapper {
   @Select("select table_name tableName, engine, table_comment tableComment, create_time createTime from information_schema.tables"
         + " where table_schema = (select database())")
   List<Map<String, Object>> list();

   @Select("select count(*) from information_schema.tables where table_schema = (select database())")
   int count(Map<String, Object> map);

   @Select("select table_name tableName, engine, table_comment tableComment, create_time createTime from information_schema.tables \r\n"
         + "    where table_schema = (select database()) and table_name = #{tableName}")
   Map<String, String> get(String tableName);

   @Select("select column_name columnName, data_type dataType, column_comment columnComment, column_key columnKey, extra from information_schema.columns\r\n"
         + " where table_name = #{tableName} and table_schema = (select database()) order by ordinal_position")
   List<Map<String, String>> listColumns(String tableName);
}
  • 自动生成代码的时候用到的数据语句1:

 

@Select("select table_name tableName, engine, table_comment tableComment, create_time createTime from information_schema.tables"
      + " where table_schema = (select database())")
List<Map<String, Object>> list();

 

SELECT table_name tableName, ENGINE, table_comment tableComment, create_time createTime FROM information_schema.tables

 

根据库名查数据库的表名、引擎、表注解、创建时间

SELECT table_name tableName, ENGINE, table_comment tableComment, create_time createTime FROM information_schema.tables  WHERE table_schema = 'jtdb'

备注:jdbc为库名

 

 

  • 自动生成代码的时候用到的数据语句2:

 

@Select("select count(*) from information_schema.tables where table_schema = (select database())")
int count(Map<String, Object> map);

SELECT DATABASE()       此语句是查询当前的数据库库名

 

SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'mtshop'       此语句是查询mtshop数据库有多少表

 

 

 

  • 自动生成代码的时候用到的数据语句3:

 

@Select("select table_name tableName, engine, table_comment tableComment, create_time createTime from information_schema.tables \r\n"
      + "    where table_schema = (select database()) and table_name = #{tableName}")
Map<String, String> get(String tableName);

SELECT table_name tableName, ENGINE, table_comment tableComment, create_time createTime FROM information_schema.tables 

WHERE table_schema = (SELECT DATABASE()) AND table_name = "user"     

查询当前库的表名为user的这些字段

 

 

  • 自动生成代码的时候用到的数据语句4:

 

@Select("select column_name columnName, data_type dataType, column_comment columnComment, column_key columnKey, extra from information_schema.columns\r\n"
      + " where table_name = #{tableName} and table_schema = (select database()) order by ordinal_position")
List<Map<String, String>> listColumns(String tableName);

SELECT column_name columnName, data_type dataType, column_comment columnComment, column_key columnKey, extra FROM information_schema.columns

WHERE table_name = 'testuser' AND table_schema = (SELECT DATABASE()) ORDER BY ordinal_position

这个语句是查询当前数据库的testuser表的 这些字段

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值