# 实体SQL工具
**Repository Path**: caunock/sql-util
## Basic Information
- **Project Name**: 实体SQL工具
- **Description**: 提供一套高效、便捷的数据库操作工具集,
包括多数据源连接池、SQL语句执行工具类、SQL构造工具以及从实体类构造SQL的工具。
亦可以通过实体快速构造web页面。
帮助开发者简化数据库操作,提高开发效率和代码质量。
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 7
- **Created**: 2024-02-21
- **Last Updated**: 2024-02-21
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## 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的工具,
> 亦可以通过实体快速构造web页面,
> 帮助开发者简化数据库操作,提高开发效率和代码质量。
## 代码示例
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 | 从实体类快速构造web页面 |
## 第一步 增加 JitPack 仓库
```xml
jitpack.io
https://jitpack.io
```
## 第二步 引入jar
1.3.0版本后升级到jdk 17 SpringBoot 3.2.2
继续使用jdk 8请查看jdk8分支
```xml
com.gitee.wb04307201
sql-util
1.3.4
```
## 第三步 使用工具
#### 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