Skip to main content

4.3 Associated Id

IsNull判断

Query all TreeNodes with parentId being null, i.e. root nodes.

TreeNodeTable table = TreeNodeTable.$;
List<TreeNode> rootNodes = sqlClient
.createQuery(table)
.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.

@Nullable Long parentId = ...Omitted...;

TreeNodeTable table = TreeNodeTable.$;
List<TreeNode> rootNodes = sqlClient
.createQuery(table)
.where(table.parentId().eq(parentId))
.select(table)
.execute();