• 首页
  • 产品中心
    • 数式Oinone四大产品

      低代码开发平台无代码开发平台集成开发平台AI大模型开发
    • 数式Oinone体系能力

      用户与组织权限管理文件管理消息中心国际化业务审计
    • 数式Oinone核心产品特性

      低无一体面向软件公司场景无限制应用级扩容可分可合
  • 服务中心
    • 客户服务

      预约演示方案咨询私有部署找人定制
    • 开发者

      问答下载
    • Oinone学院

      社区学习

    《精讲面向软件公司的低代码平台——以Oinone为例》

  • 合作伙伴
    渠道申请伙伴名录专家库
  • 关于数式
0571-88757863

Data Operation:Custom Sort Fields and Sorting Rules During Query


Ⅰ、Specify Fields for Sorting

The platform's default sorting fields, refer to IdModel, sorted in descending order by creation time and ID: ordering = "createDate DESC, id DESC"

(Ⅰ)Specify Sorting in the Model

Add sorting fields to the model definition. @Model.Advanced(ordering = "xxxxx DESC, yyyy DESC")

@Model.model(PetShop.MODEL_MODEL)
@Model(displayName = "Pet Shop", summary="Pet Shop", labelFields ={"shopName"})
@Model.Code(sequence = "DATE_ORDERLY_SEQ", prefix = "P", size=6, step=1, initial = 10000, format = "yyyyMMdd")
@Model.Advanced(ordering = "createDate DESC")
public class PetShop extends AbstractDemoIdModel {
    public static final String MODEL_MODEL="demo.PetShop";
    // Other code
}

(Ⅱ)Custom Sorting Rules in Page Queries

  • API reference: pro.shushi.pamirs.meta.api.dto.condition.Pagination#orderBy
public <G, R> Pagination<T> orderBy(SortDirectionEnum direction, Getter<G, R> getter) {
    if (null == getSort()) {
        setSort(new Sort());
    }
    getSort().addOrder(direction, getter);
    return this;
}
  • Specific Example
@Function.Advanced(type= FunctionTypeEnum.QUERY)
@Function.fun(FunctionConstants.queryPage)
@Function(openLevel = {FunctionOpenEnum.API})
public Pagination<PetShop> queryPage(Pagination<PetShop> page, IWrapper<PetShop> queryWrapper){
    page.orderBy(SortDirectionEnum.DESC, PetShop::getCreateDate);
    page = new PetShop().queryPage(page, queryWrapper);
    return page;
}

(Ⅲ)Specify in the Query Wrapper

  • API reference: pro.shushi.pamirs.framework.connectors.data.sql.AbstractWrapper#orderBy
@Override
public Children orderBy(boolean condition, boolean isAsc, R... columns) {
    if (ArrayUtils.isEmpty(columns)) {
        return typedThis;
    }
    SqlKeyword mode = isAsc ? ASC : DESC;
    for (R column : columns) {
        doIt(condition, ORDER_BY, columnToString(column), mode);
    }
    return typedThis;
}

Specific Example

public List<PetShop> queryList(String name) {
    List<PetShop> petShops = Models.origin().queryListByWrapper(
        Pops.<PetShop>lambdaQuery().from(PetShop.MODEL_MODEL)
        .orderBy(true, true, PetShop::getCreateDate)
        .orderBy(true, true, PetShop::getId)
        .like(PetShop::getShopName, name));
    return petShops;
}

Ⅱ、Disable Sorting for Queries

(Ⅰ)Turn Off the Platform's Default Sorting Fields by Setting the Model's Ordering to: ordering = "1=1"

Add sorting fields to the model definition. @Model.Advanced(ordering = "1=1")

@Model.model(PetShop.MODEL_MODEL)
@Model(displayName = "Pet Shop", summary="Pet Shop", labelFields ={"shopName"})
@Model.Code(sequence = "DATE_ORDERLY_SEQ", prefix = "P", size=6, step=1, initial = 10000, format = "yyyyMMdd")
@Model.Advanced(ordering = "1=1")
public class PetShop extends AbstractDemoIdModel {
    public static final String MODEL_MODEL="demo.PetShop";
    // Other code
}

In ORDER BY 1=1, 1=1 is a conditional expression that always returns true (or 1 in some databases) because 1 equals 1. Therefore, this condition does not actually change the sorting result, and the result will still be sorted in the default order. This syntax is commonly used in scenarios where SQL statements are dynamically generated to sort by order when the specific column names are unknown.

So, ORDER BY 1=1 is actually equivalent to not using an ORDER BY clause, or sorting in the default order.

(Ⅱ)Set the Sortable Property During Query

// Example 1:
LambdaQueryWrapper<PetShop> query = Pops.<PetShop>lambdaQuery();
query.from(PetShop.MODEL_MODEL);
query.setSortable(Boolean.FALSE);
query.orderBy(true, true, PetShop::getId);
List<PetShop> petShops2 = new PetShop().queryList(query);
System.out.printf(petShops2.size() + "");

// Example 2:
List<PetShop> petShops3 = new PetShop().queryList(
    Pops.<PetShop>lambdaQuery().from(PetShop.MODEL_MODEL).setSortable(Boolean.FALSE));
System.out.printf(petShops3.size() + "");

// Example 3:
IWrapper<PetShop> wrapper = Pops.<PetShop>lambdaQuery()
.from(PetShop.MODEL_MODEL).setBatchSize(-1).setSortable(Boolean.FALSE);
List<PetShop> petShops4 = new PetShop().queryList(wrapper);
System.out.printf(petShops4.size() + "");

// Example 4:
QueryWrapper<PetShop> wrapper2 = new QueryWrapper<PetShop>().from(PetShop.MODEL_MODEL).setSortable(Boolean.FALSE);
List<PetShop> petShops5 = new PetShop().queryList(wrapper2);
System.out.printf(petShops5.size() + "");
Edit this page
Last Updated:1/15/26, 4:02 AM
Prev
Data Operation:How to Customize Excel Import and Export Functions
Next
Data Operations:Custom RSQL Placeholders and Their Usage in Permissions
默认页脚
Copyright © 2026 Mr.Hope