4.1 Base Usage
The following three ways of writing are equivalent
Use multiple filters
- Java
- Kotlin
String name = ...Omitted...;
int edition = ...Omitted...;
BookTable table = BookTable.$;
List<Book> books = sqlClient
.createQuery(table)
.where(table.name().ilike(name))
.where(table.edition().eq(edition))
.select(table)
.execute();
val name: String = ...Omitted...
val edition: Int = ...Omitted...
val books = sqlClient
.createQuery(Book::class) {
where(table.name ilike name)
where(table.edition eq edition)
select(table)
}
.execute()
Filter with multiple arguments
- Java
- Kotlin
String name = ...Omitted...;
int edition = ...Omitted...;
BookTable table = BookTable.$;
List<Book> books = sqlClient
.createQuery(table)
.where(
table.name().ilike(name),
table.edition().eq(edition)
)
.select(table)
.execute();
val name: String = ...Omitted...
val edition: Int = ...Omitted...
val books = sqlClient
.createQuery(Book::class) {
where(
table.name ilike name,
table.edition eq edition
)
select(table)
}
.execute();
Logic And
- Java
- Kotlin
String name = ...Omitted...;
int edition = ...Omitted...;
BookTable table = BookTable.$;
List<Book> books = sqlClient
.createQuery(table)
.where(
Predicate.and(
table.name().ilike(name),
table.edition().eq(edition)
)
)
.select(table)
.execute();
val name: String = ...Omitted...
val edition: Int = ...Omitted...
val books = sqlClient
.createQuery(Book::class) {
where(
and(
table.name ilike name,
table.edition eq edition
)
)
select(table)
}
.execute()
Suggestion
The above three ways are completely equivalent. However, there is no doubt that the first one is the easiest, so it is recommended.