update docs

This commit is contained in:
开源海哥 2023-05-22 08:25:40 +08:00
parent e45df191df
commit 349d6eacc2
3 changed files with 26 additions and 4 deletions

View File

@ -58,7 +58,7 @@ export default defineConfig({
{
text: '基础功能',
items: [
{text: '增删改', link: '/zh/base/add-delete-update'},
{text: '增改', link: '/zh/base/add-delete-update'},
{text: '查询和分页', link: '/zh/base/query'},
{text: '批量操作', link: '/zh/base/batch'},
{text: 'QueryWrapper', link: '/zh/base/querywrapper'},

View File

@ -30,7 +30,7 @@ insert into tb_account(id,nickname, .....) values
## `Db.executeBatch` 方法
以下是使用 `Db.executeBatch` 进行批量插入的示例:
`Db.executeBatch` 可以用于进行批量的插入、修改和删除,以下是使用 `Db.executeBatch` 进行批量插入的示例:
```java
List<Account> accounts = ....
@ -39,7 +39,12 @@ Db.executeBatch(accounts.size(), 1000, AccountMapper.class, (mapper, index) -> {
mapper.insert(account);
});
```
这个是通过 JDBC 的 `Statement.executeBatch()` 进行批量执行;这个在大批量数据执行的时候,效率要比 `BaseMapper.insertBatch` 高出许多;
`Db.executeBatch` 是通过 JDBC 的 `Statement.executeBatch()` 进行批量执行;这个在大批量数据执行的时候,效率要比 `BaseMapper.insertBatch` 高出许多;
::: tip 提示
我看到有一些同学担心 `BaseMapper.insertBatch` 被误用,在 `IService` 中通过使用 `Db.executeBatch` 重写了 Service 的 `insertBatch` 方法,这也是没问题的。但还是需要明白,
`BaseMapper.insertBatch``Db.executeBatch` 的底层实现差异,以及不同的使用场景。
:::
## `Db.updateBatch` 方法
@ -66,7 +71,7 @@ Db.updateBatch(sql, new BatchArgsSetter() {
});
```
虽然这个方法叫 `updateBatch`,但一样可以执行 `insert``update` 等任何 SQL 这个方法类似 Spring 的 `jdbcTemplate.batchUpdate()` 方法。
虽然这个方法叫 `updateBatch`,但一样可以执行 `insert``delete`、`update` 等任何 SQL 这个方法类似 Spring 的 `jdbcTemplate.batchUpdate()` 方法。
## `Db.updateEntitiesBatch` 方法

View File

@ -171,6 +171,23 @@ SELECT * FROM tb_account
WHERE user_name LIKE ?
```
## where 动态条件 3
```java 1,5
String name = null;
QueryWrapper queryWrapper = QueryWrapper.create()
.select().from(ACCOUNT)
.where(ACCOUNT.ID.ge(100)) // when....
.and(ACCOUNT.USER_NAME.like(name).when(StringUtil::isNotBlank));
```
其查询生成的 Sql 如下:
```sql
SELECT * FROM tb_account
WHERE id >= ?
```
## where select
```java
QueryWrapper queryWrapper = QueryWrapper.create()