我正在使用下面的代码
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);