Java jOOQ如何使用可选排序
我有一个从表中选择人员的查询Java jOOQ如何使用可选排序,java,sql,jooq,Java,Sql,Jooq,我有一个从表中选择人员的查询 SelectConditionStep<PersonRecord> select = context .selectFrom(Tables.PERSON) .where(Tables.PERSON.ISDELETED.eq(false)); if(searchValue != null && searchValue.length() > 0){ select.and(Tables.PERSON.LASTNA
SelectConditionStep<PersonRecord> select = context
.selectFrom(Tables.PERSON)
.where(Tables.PERSON.ISDELETED.eq(false));
if(searchValue != null && searchValue.length() > 0){
select.and(Tables.PERSON.LASTNAME.likeIgnoreCase(String.format("%%%s%%", searchValue)));
}
List<PersonRecord> dbPersons = select
.orderBy(Tables.PERSON.LASTNAME, Tables.PERSON.FIRSTNAME, Tables.PERSON.ID)
.limit(length).offset(start)
.fetch();
SelectConditionStep选择=上下文
.selectFrom(Tables.PERSON)
.式中(表.人.被删除.情商(假));
if(searchValue!=null&&searchValue.length()>0){
选择.and(Tables.PERSON.LASTNAME.likeIgnoreCase(String.format(“%%s%%”,searchValue));
}
List dbPersons=select
.orderBy(Tables.PERSON.LASTNAME、Tables.PERSON.FIRSTNAME、Tables.PERSON.ID)
.极限(长度).偏移(起点)
.fetch();
这段代码运行得很好。因为我在datatables表中显示数据,所以我需要具有可选/动态排序功能。到目前为止,我还没有找到解决方案。现在我自己找到了解决方案:
Collection<SortField<?>> sortFields = new ArrayList<>();
sortFields.add(Tables.PERSON.FIRSTNAME.asc());
List<PersonRecord> dbPersons = select
.orderBy(sortFields)
.limit(length).offset(start)
.fetch();
收藏