我正在使用下面的代码

Transaction transaction = Transaction.current();
        SelectQuery<Record> selectQuery = transaction.selectQuery();
        selectQuery.addSelect(Folder.FOLDER.FOLDER_RSN, Routines.fFoldernumber(Folder.FOLDER.FOLDER_RSN).as("FolderNumber"),
                Folder.FOLDER.FOLDER_NAME, Folder.FOLDER.FOLDER_TYPE);
selectQuery.addFrom(FolderPeople.FOLDER_PEOPLE);


现在我想在FolderNumber上添加OrderBy,如下所示

selectQuery.addOrderBy("FolderNumber")


在上述情况下如何添加OrderBy?

最佳答案

jOOQ生成的存储函数实现了org.jooq.Field,因此您只需将它们添加到ORDER BY子句中:

selectQuery.addOrderBy(fFoldernumber(...));


除了重复整个调用,您可能还需要考虑为存储的函数调用创建本地引用:

Field<?> folder = Routines.fFoldernumber(Folder.FOLDER.FOLDER_RSN).as("FolderNumber");
// ...
selectQuery.addSelect(..., folder);
selectQuery.addOrderBy(folder);

07-24 15:31