This commit is contained in:
redkale
2023-12-30 08:53:49 +08:00
parent fe6a5dd91c
commit e6f22a1f18
11 changed files with 84 additions and 35 deletions

View File

@@ -1,4 +1,32 @@
# DB数据源
   DataSource是数据层操作的抽象接口
## 注解说明
|注解类名 | 功能描述|
| --- | --- |
|@Column |标记字段与JPA用法一致 |
|@Entity |标记实体类与JPA用法一致 |
|@Id |标记主键字段与JPA用法一致 |
|@Table |标记表的别名与JPA用法一致 |
|@Transient |标记是否为表对应的字段与JPA用法一致 |
|@VirtualEntity |用于非数据库表对应的Entity类且仅用于开启缓存模式的DataSource |
|@DistributeTable |标记表进行分表分库存储, 与DistributeTableStrategy接口结合使用 |
|@FilterColumn |用于FilterBean过滤类的字段设置 |
|@FilterJoinColumn |用于FilterBean过滤类的关联表字段设置 |
|@FilterGroup | 用于FilterBean过滤类的过滤条件分组设置 |
## 操作方法
|系列方法 | 功能描述|
| --- | --- |
|insert |插入实体 |
|delete |删除实体 |
|update |更新实体 |
|updateColumn |更新数据的部分字段 |
|find |查找单个对象 |
|queryList |查询对象的List集合 |
|querySheet |查询对象的Sheet页式集合 |
|getNumberXXX |统计查询,用于查询字段的总和、最大值、平均值等数据 |
|queryColumnXXX |单个字段数据查询和字段的统计查询 |
|nativeXXX |直接运行SQL语句用于复杂的关联查询与更新(仅限DataSqlSource) |
## 配置数据源
```properties
@@ -37,23 +65,28 @@ public class Account {
  新增实体对象:
```java
//新增单个
Account account = new Account();
account.setAccountid("account1");
account.setAccountName("Hello");
account.setCreateTime(System.currentTimeMillis());
source.insert(account);
@Resource(name = "platf")
private DataSource source;
//异步新增多个
Account a1 = new Account();
a1.setAccountid("account1");
a1.setAccountName("Hello1");
a1.setCreateTime(System.currentTimeMillis());
Account a2 = new Account();
a2.setAccountid("account2");
a2.setAccountName("Hello2");
a2.setCreateTime(System.currentTimeMillis());
source.insertAsync(a1, a2);
public void insertTest() {
//新增单个
Account account = new Account();
account.setAccountid("account1");
account.setAccountName("Hello");
account.setCreateTime(System.currentTimeMillis());
source.insert(account);
//异步新增多个
Account a1 = new Account();
a1.setAccountid("account1");
a1.setAccountName("Hello1");
a1.setCreateTime(System.currentTimeMillis());
Account a2 = new Account();
a2.setAccountid("account2");
a2.setAccountName("Hello2");
a2.setCreateTime(System.currentTimeMillis());
source.insertAsync(a1, a2);
}
```
  修改实体对象: