1. 基本查询
Jimmer中有两个概念
- 查询多列
- 查询一个对象列,并指定被查询对象的多个属性
它们是完全不同的概念
查询多列
- Java
- Kotlin
BookTable table = BookTable.$;
List<Tuple3<Long, String, Integer>> tuples = sqlClient
.createQuery(table)
.where(table.name().eq("GraphQL in Action"))
.orderBy(table.edition().desc())
.select(
table.id(),
table.name(),
table.edition()
)
.execute();
val tuples = sqlClient
.createQuery(Book::class) {
where(table.name eq "GraphQL in Action")
orderBy(table.edition.desc())
select(
table.id,
table.name,
table.edtion
)
}
.execute()
在Jimmer中,除了只返回一列的查询外,其他都是多列查询。这个例子查询了三列,故返回类型为Tuple3<T1, T2, T3>
。
等到如下数据
[
{
"_1" : 12,
"_2" : "GraphQL in Action",
"_3" : 3
}, {
"_1" : 11,
"_2" : "GraphQL in Action",
"_3" : 2
}, {
"_1" : 10,
"_2" : "GraphQL in Action",
"_3" : 1
}
]