4.3 Associated Id
IsNull判断
Query all TreeNode
s with parentId
being null, i.e. root nodes.
- Java
- Kotlin
TreeNodeTable table = TreeNodeTable.$;
List<TreeNode> rootNodes = sqlClient
.createQuery(table)
.where(table.parentId().isNull())
.select(table)
.execute();
val rootNodes = sqlClient
.createQuery(TreeNode::class) {
where(table.parentId.isNull())
select(table)
}
.execute()
tip
In the code above, parentId
is automatically generated by Jimmer at compile time based on the many-to-one property TreeNode.parent
,
even if the developer does not define the @IdView property named parentId
.
Judgment of any value
In fact, eq
supports null parameters. When the parameter of eq
is null, is null
is rendered:
caution
Note: The eqIf
of java and eq?
of kotlin are different, null is considered a dynamic query and does not render any SQL condition.
- Java
- Kotlin
@Nullable Long parentId = ...Omitted...;
TreeNodeTable table = TreeNodeTable.$;
List<TreeNode> rootNodes = sqlClient
.createQuery(table)
.where(table.parentId().eq(parentId))
.select(table)
.execute();
val parentId: Long? = ...Omitted...;
val rootNodes = sqlClient
.createQuery(TreeNode::class) {
where(table.parentId eq parentId)
select(table)
}
.execute()