# sql-util 实体SQL工具
[![](https://jitpack.io/v/com.gitee.wb04307201/sql-util.svg)](https://jitpack.io/#com.gitee.wb04307201/sql-util)
[![star](https://gitee.com/wb04307201/sql-util/badge/star.svg?theme=dark)](https://gitee.com/wb04307201/sql-util)
[![fork](https://gitee.com/wb04307201/sql-util/badge/fork.svg?theme=dark)](https://gitee.com/wb04307201/sql-util)
[![star](https://img.shields.io/github/stars/wb04307201/sql-util)](https://github.com/wb04307201/sql-util)
[![fork](https://img.shields.io/github/forks/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
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
```
## 第二步 引入jar
1.3.0版本后升级到jdk17 SpringBoot3+
继续使用jdk 8请查看jdk8分支
```xml
<dependency>
<groupId>com.gitee.wb04307201</groupId>
<artifactId>sql-util</artifactId>
<version>1.3.6</version>
</dependency>
```
## 第三步 使用工具
#### 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<Integer, Object> 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<Map<String, Object>> list = ExecuteSqlUtils.executeQuery(connection, "select * from test_user where user_name = ?", params, new TypeReference<Map<String, Object>>() {
});
list = MutilConnectionPool.run("test", conn -> ExecuteSqlUtils.executeQuery(conn, "select * from test_user where user_name = ?", params, new TypeReference<Map<String, Object>>() {
}));
// 执行删除的sql语句
MutilConnectionPool.run("test", conn -> ExecuteSqlUtils.executeUpdate(conn, "delete from test_user where user_name = ?", params));
connection.close();
```
#### 在测试SQL、ModelSqlUtils前,请先创建一个测试实体类,例如
```java
package cn.wubo.sql.util.test;
import cn.wubo.sql.util.annotations.Column;
import cn.wubo.sql.util.annotations.Key;
import cn.wubo.sql.util.annotations.Table;
import cn.wubo.sql.util.enums.ColumnType;
import lombok.Data;
import java.util.Date;
@Data
@Table(value = "test_user", desc = "用户")
public class User {
@Key
@Column(value = "id")
private String id;
@Column(value = "user_name",desc = "用户名", type = ColumnType.VARCHAR, length = 20)
private String userName;
@Column(value = "department")
private String department;
@Column(value = "birth", type = ColumnType.DATE)
private Date birth;
@Column(value = "birth1")
private Date birth1;
@Column(value = "age", type = ColumnType.NUMBER, precision = 10, scale = 0)
private Integer age;
@Column(value = "age1")
private Integer age1;
}
```
#### SQL使用示例
```java
// 判断数据源是否加载
if (Boolean.FALSE.equals(MutilConnectionPool.check("test"))) {
// 加载数据源
MutilConnectionPool.init("test", "jdbc:h2:file:./data/demo;AUTO_SERVER=TRUE", "sa", "");
}
SQL<User> userSQL = new SQL<User>(){};
// 判断表是否存在
if(Boolean.TRUE.equals(MutilConnectionPool.run("test",conn -> userSQL.isTableExists(conn)))){
// 删除表
MutilConnectionPool.run("test",conn -> userSQL.drop().dropTable(conn));
}
// 创建表
MutilConnectionPool.run("test",conn -> userSQL.create().createTable(conn));
// 插入数据
MutilConnectionPool.run("test",conn -> userSQL.insert().addSet("user_name","11111").executeUpdate(conn));
// 更新数据
MutilConnectionPool.run("test",conn -> userSQL.update().addSet("user_name","22222").addWhereEQ("user_name","11111").executeUpdate(conn));
// 查询数据
List<User> userList = MutilConnectionPool.run("test",conn -> userSQL.select().addWhereEQ("user_name","22222").executeQuery(conn));
// 删除数据
MutilConnectionPool.run("test",conn -> userSQL.delete().addWhereEQ("user_name","22222").executeUpdate(conn));
```
#### ModelSqlUtils使用示例
```java
// 判断数据源是否加载
if (Boolean.FALSE.equals(MutilConnectionPool.check("test"))) {
// 加载数据源
MutilConnectionPool.init("test", "jdbc:h2:file:./data/demo;AUTO_SERVER=TRUE", "sa", "");
}
没有合适的资源?快使用搜索试试~ 我知道了~
sql-util 实体SQL工具.zip
共53个文件
java:37个
js:2个
png:2个
需积分: 1 0 下载量 172 浏览量
2024-05-22
15:48:03
上传
评论
收藏 1MB ZIP 举报
温馨提示
提供一套高效、便捷的数据库操作工具集, 包括多数据源连接池、SQL语句执行工具类、SQL构造工具类、从实体类构造SQL工具类。 亦可以通过实体快速构造web页面。 帮助开发者简化数据库操作,提高开发效率和代码质量。
资源推荐
资源详情
资源评论
收起资源包目录
sql-util 实体SQL工具.zip (53个子文件)
sql-util-master
pom.xml 3KB
src
main
resources
template
table.ftl 21KB
META-INF
resources
entity
web
static
echarts
5.5.0
echarts.min.js 1001KB
layui
2.9.8
layui.js 348KB
font
iconfont.ttf 53KB
iconfont.woff2 29KB
iconfont.svg 323KB
iconfont.eot 53KB
iconfont.woff 34KB
css
layui.css 122KB
java
cn
wubo
sql
util
ExecuteSqlUtils.java 9KB
utils
FunctionUtils.java 3KB
MapUtils.java 2KB
StringUtils.java 2KB
cache
MemoryCache.java 2KB
web
EntityWebService.java 9KB
EnableEntityWeb.java 267B
EntityWebQuery.java 197B
EntityWebConfig.java 6KB
SQL.java 33KB
enums
ColumnType.java 260B
StatementCondition.java 469B
EditType.java 263B
DriverNameType.java 2KB
GenerationType.java 77B
StatementType.java 309B
entity
EntityUtils.java 9KB
TableModel.java 8KB
exception
SQLRuntimeException.java 258B
ConnectionPoolException.java 377B
EntityWebException.java 280B
ExecuteSqlException.java 177B
ModelSqlException.java 251B
StringException.java 170B
TableModelException.java 178B
MutilConnectionPool.java 8KB
annotations
Column.java 3KB
Edit.java 2KB
Table.java 1KB
Ds.java 1KB
Condition.java 293B
Item.java 885B
View.java 2KB
Key.java 277B
TypeReference.java 2KB
result
Result.java 606B
ModelSqlUtils.java 7KB
LICENSE 11KB
.gitignore 17B
img.png 184KB
README.md 12KB
img_1.png 49KB
项目说明.zip 68KB
共 53 条
- 1
资源评论
忘却的纪念
- 粉丝: 1204
- 资源: 184
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功