diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 1992dd72..6ed879d4 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -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'}, diff --git a/docs/zh/base/batch.md b/docs/zh/base/batch.md index 3f1c0f18..33553f4d 100644 --- a/docs/zh/base/batch.md +++ b/docs/zh/base/batch.md @@ -30,7 +30,7 @@ insert into tb_account(id,nickname, .....) values ## `Db.executeBatch` 方法 -以下是使用 `Db.executeBatch` 进行批量插入的示例: +`Db.executeBatch` 可以用于进行批量的插入、修改和删除,以下是使用 `Db.executeBatch` 进行批量插入的示例: ```java List 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` 方法 diff --git a/docs/zh/base/querywrapper.md b/docs/zh/base/querywrapper.md index 7a88f74e..c3912b3a 100644 --- a/docs/zh/base/querywrapper.md +++ b/docs/zh/base/querywrapper.md @@ -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()