跳到主要内容

4.1 基本用法

以下三种写法等价

使用多个where​

String name = ...略...;
int edition = ...略...;

BookTable table = BookTable.$;
List<Book> books = sqlClient
.createQuery(table)
.where(table.name().ilike(name))
.where(table.edition().eq(edition))
.select(table)
.execute();

where带多个参数​

String name = ...略...;
int edition = ...略...;

BookTable table = BookTable.$;
List<Book> books = sqlClient
.createQuery(table)
.where(
table.name().ilike(name),
table.edition().eq(edition)
)
.select(table)
.execute();

使用逻辑与​

String name = ...略...;
int edition = ...略...;

BookTable table = BookTable.$;
List<Book> books = sqlClient
.createQuery(table)
.where(
Predicate.and(
table.name().ilike(name),
table.edition().eq(edition)
)
)
.select(table)
.execute();

建议​

以上三种写法完全等价。然而,毫无疑问,第一种是最简单的,故而推荐。