mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 09:38:26 +08:00
docs: update docs
This commit is contained in:
parent
83791f66f7
commit
5b6126738a
@ -61,6 +61,7 @@ export default defineConfig({
|
|||||||
{text: '关联查询', link: '/zh/base/relations-query'},
|
{text: '关联查询', link: '/zh/base/relations-query'},
|
||||||
{text: '批量操作', link: '/zh/base/batch'},
|
{text: '批量操作', link: '/zh/base/batch'},
|
||||||
{text: 'QueryWrapper', link: '/zh/base/querywrapper'},
|
{text: 'QueryWrapper', link: '/zh/base/querywrapper'},
|
||||||
|
{text: 'QueryWrapperChain', link: '/zh/base/query-wrapper-chain'},
|
||||||
{text: 'Db + Row', link: '/zh/base/db-row'},
|
{text: 'Db + Row', link: '/zh/base/db-row'},
|
||||||
{text: 'IService', link: '/zh/base/service'},
|
{text: 'IService', link: '/zh/base/service'},
|
||||||
{text: 'SpringBoot 配置文件', link: '/zh/base/configuration'},
|
{text: 'SpringBoot 配置文件', link: '/zh/base/configuration'},
|
||||||
|
|||||||
75
docs/zh/base/query-wrapper-chain.md
Normal file
75
docs/zh/base/query-wrapper-chain.md
Normal 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 等
|
||||||
|
|
||||||
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.mybatisflex.test.service;
|
package com.mybatisflex.test.service;
|
||||||
|
|
||||||
import com.mybatisflex.test.model.Article;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
@ -38,7 +37,7 @@ class ArticleServiceTest {
|
|||||||
articleService.queryChain()
|
articleService.queryChain()
|
||||||
.select(ARTICLE.ALL_COLUMNS)
|
.select(ARTICLE.ALL_COLUMNS)
|
||||||
.from(ARTICLE)
|
.from(ARTICLE)
|
||||||
.where(Article::getAccountId).eq(1)
|
.where(ARTICLE.ID.ge(100))
|
||||||
.list()
|
.list()
|
||||||
.forEach(System.out::println);
|
.forEach(System.out::println);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user