docs: update docs

This commit is contained in:
开源海哥 2023-07-22 15:24:02 +08:00
parent 83791f66f7
commit 5b6126738a
3 changed files with 77 additions and 2 deletions

View File

@ -61,6 +61,7 @@ export default defineConfig({
{text: '关联查询', link: '/zh/base/relations-query'},
{text: '批量操作', link: '/zh/base/batch'},
{text: 'QueryWrapper', link: '/zh/base/querywrapper'},
{text: 'QueryWrapperChain', link: '/zh/base/query-wrapper-chain'},
{text: 'Db + Row', link: '/zh/base/db-row'},
{text: 'IService', link: '/zh/base/service'},
{text: 'SpringBoot 配置文件', link: '/zh/base/configuration'},

View File

@ -0,0 +1,75 @@
# QueryWrapperChain
`QueryWrapperChain.java` 是一个对 `QueryWrapper` 进行链式调用封装的一个类,在 Service 中,
我们可以调用 `service.queryChain()` 获得该实例。
例如,查询文章列表代码如下:
```java
@SpringBootTest
class ArticleServiceTest {
@Autowired
ArticleService articleService;
@Test
void testChain() {
List<Article> articles = articleService.queryChain()
.select(ARTICLE.ALL_COLUMNS)
.from(ARTICLE)
.where(ARTICLE.ID.ge(100))
.list();
}
}
```
若不是在 Service 中,我们也可以通过 `QueryWrapperChain.create` 方法,自己创建一个 `QueryWrapperChain` 实例,代码如下:
```java
List<Article> articles = QueryWrapperChain.create(mapper)
.select(ARTICLE.ALL_COLUMNS)
.from(ARTICLE)
.where(ARTICLE.ID.ge(100))
.list();
```
## QueryWrapperChain 的方法
- one():获取一条数据
- list():获取多条数据
- page():分页查询
- remove():删除数据
- update(entity):更新数据
- count():查询数据条数
- exists():是否存在,判断 count 是否大于 0
## 扩展方法
### `one()` 系列方法
- one():获取一条数据
- oneAs(asType):查询数据,并直接转换为 vo、dto 等
- oneWithRelations查询一条数据及其关联数据
- oneWithRelationsAs查询一条数据及其关联数据并直接转换为 vo、dto 等
- oneOpt返回 Optional 类型,获取一条数据
- oneAsOpt(asType):返回 Optional 类型,查询数据,并直接转换为 vo、dto 等
- oneWithRelationsOpt返回 Optional 类型,查询一条数据及其关联数据
- oneWithRelationsAsOpt返回 Optional 类型,查询一条数据及其关联数据,并直接转换为 vo、dto 等
### `list()` 系列方法
- list():查询数据列表
- listWithRelations():查询数据列表极其关联数据
- listAs():查询数据列表,并直接转换为 vo、dto 等
- listWithRelationsAs():查询数据列表,及其关联数据,并直接转换为 vo、dto 等
### `page()` 系列方法
- page(page):分页查询数据列表
- pageWithRelations(page):分页查询数据列表极其关联数据
- pageAs(page):分页查询数据列表,并直接转换为 vo、dto 等
- pageWithRelationsAs(page):分页查询数据列表,及其关联数据,并直接转换为 vo、dto 等

View File

@ -16,7 +16,6 @@
package com.mybatisflex.test.service;
import com.mybatisflex.test.model.Article;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@ -38,7 +37,7 @@ class ArticleServiceTest {
articleService.queryChain()
.select(ARTICLE.ALL_COLUMNS)
.from(ARTICLE)
.where(Article::getAccountId).eq(1)
.where(ARTICLE.ID.ge(100))
.list()
.forEach(System.out::println);
}