# 实体SQL工具
**Repository Path**: wb04307201/sql-util
## Basic Information
- **Project Name**: 实体SQL工具
- **Description**: 提供一套高效、便捷的数据库操作工具集,包括多数据源连接池管理类、SQL语句执行类、SQL语句构建器、实体类构建SQL语句并执行工具类,亦可以快速构造普通的增删改查页面和功能。
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 74
- **Forks**: 7
- **Created**: 2022-10-31
- **Last Updated**: 2025-04-03
## Categories & Tags
**Categories**: dbmanager
**Tags**: SQL, 工具类, 低代码
## README
# sql-util 实体SQL工具
[](https://jitpack.io/#com.gitee.wb04307201/sql-util)
[](https://gitee.com/wb04307201/sql-util)
[](https://gitee.com/wb04307201/sql-util)
[](https://github.com/wb04307201/sql-util)
[](https://github.com/wb04307201/sql-util)
  
> 提供一套高效、便捷的数据库操作工具集,
> 包括多数据源连接池管理类、SQL语句执行类、SQL语句构建器、实体类构建SQL语句并执行工具类,
> 亦可以快速构造普通的增删改查页面和功能。
## 代码示例
1. 使用[实体SQL工具](https://gitee.com/wb04307201/sql-util)实现的[实体SQL工具Demo](https://gitee.com/wb04307201/sql-util-demo)
2. 使用[文档在线预览](https://gitee.com/wb04307201/file-preview-spring-boot-starter)、[多平台文件存储](https://gitee.com/wb04307201/file-storage-spring-boot-starter)、[实体SQL工具](https://gitee.com/wb04307201/sql-util)实现的[文件预览Demo](https://gitee.com/wb04307201/file-preview-demo)
3. 使用[多平台文件存储](https://gitee.com/wb04307201/file-storage-spring-boot-starter)、[实体SQL工具](https://gitee.com/wb04307201/sql-util)实现的[文件存储Demo](https://gitee.com/wb04307201/file-storage-demo)
4. 使用[消息中间件](https://gitee.com/wb04307201/message-spring-boot-starter)、[实体SQL工具](https://gitee.com/wb04307201/sql-util)实现的[消息发送代码示例](https://gitee.com/wb04307201/message-demo)
5. 使用[动态调度](https://gitee.com/wb04307201/dynamic-schedule-spring-boot-starter)、[消息中间件](https://gitee.com/wb04307201/message-spring-boot-starter)、[动态编译加载执行工具](https://gitee.com/wb04307201/loader-util)、[实体SQL工具](https://gitee.com/wb04307201/sql-util)实现的[在线编码、动态调度、发送钉钉群消息、快速构造web页面Demo](https://gitee.com/wb04307201/dynamic-schedule-demo)
## 工具
| 序号 | 工具类 | 描述 |
|----|---------------------|------------------|
| 1 | MutilConnectionPool | 多数据源连接池管理类 |
| 2 | ExecuteSqlUtils | SQL语句执行类 |
| 3 | SQL | SQL语句构建器 |
| 4 | ModelSqlUtils | 实体类构建SQL语句并执行工具类 |
| 5 | EntityWeb | 快速构造普通的增删改查页面和功能 |
## 快速开始
### 引入依赖
增加 JitPack 仓库
```xml
jitpack.io
https://jitpack.io
```
1.3.0版本后升级到jdk17 SpringBoot3+
继续使用jdk 8请查看jdk8分支
```xml
com.gitee.wb04307201
sql-util
1.3.7
```
### 使用
#### MutilConnectionPool使用示例
```java
// 判断数据源是否加载
if (Boolean.FALSE.equals(MutilConnectionPool.check("test"))) {
// 加载数据源
MutilConnectionPool.init("test", "jdbc:h2:file:./data/demo;AUTO_SERVER=TRUE", "sa", "");
}
// 获取数据源,注意使用完之后释放连接
Connection connection = MutilConnectionPool.getConnection("test");
connection.close();
// 通过传入函数式接口执行方法,内部会自动创建连接并在使用之后释放
MutilConnectionPool.run("test", conn -> null);
```
#### ExecuteSqlUtils使用示例
```java
// 判断数据源是否加载
if (Boolean.FALSE.equals(MutilConnectionPool.check("test"))) {
// 加载数据源
MutilConnectionPool.init("test", "jdbc:h2:file:./data/demo;AUTO_SERVER=TRUE", "sa", "");
}
Connection connection = MutilConnectionPool.getConnection("test");
// 判断表是否存在
Boolean check = ExecuteSqlUtils.isTableExists(connection, "test_user");
// 通过MutilConnectionPool.run检查表是否存在
check = MutilConnectionPool.run("test", conn -> ExecuteSqlUtils.isTableExists(conn, "test_user"));
Map params = new HashMap<>();
params.put(1, "123123");
// 执行插入、更新的sql语句
int count = ExecuteSqlUtils.executeUpdate(connection, "update test_user set user_name = ?", params);
count = MutilConnectionPool.run("test", conn -> ExecuteSqlUtils.executeUpdate(conn, "update test_user set user_name = ?", params));
// 执行查询的sql语句
List