Class Sort
java.lang.Object
cloud.opencode.base.core.page.Sort
Sort - Sort specification for queries
排序 - 查询排序规范
Represents an ordered collection of sort orders, each consisting of a property name and a direction (ASC or DESC). Compatible with Spring Data semantics while having no dependency on Spring Data Commons.
表示有序的排序规范集合,每项包含属性名和方向(ASC 或 DESC)。 与 Spring Data 语义兼容,但不依赖 Spring Data Commons。
Features | 主要功能:
- Fluent builder API for composing sort orders - 流式构建 API 组合排序规范
- ASC / DESC direction with null handling - 支持 ASC / DESC 及 null 处理
- Immutable value object — safe to share and cache - 不可变值对象,可安全共享和缓存
Usage Examples | 使用示例:
Sort sort = Sort.by("name").and(Sort.by(Sort.Direction.DESC, "createdAt"));
Sort descAge = Sort.by(Sort.Direction.DESC, "age");
List<Sort.Order> orders = sort.getOrders();
String sql = "ORDER BY " + sort.toSql(); // name ASC, created_at DESC
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Since:
- JDK 25, opencode-base-core V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumSort direction.static final recordA single sort order: property + direction. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic Sortby(Sort.Direction direction, String property) static Sortby(Sort.Direction direction, String... properties) static Sortby(Sort.Order... orders) static Sortstatic Sortby(List<Sort.Order> orders) booleaninthashCode()booleantoSql()Renders this Sort as a SQL ORDER BY fragment (without theORDER BYkeyword).toString()static Sortunsorted()
-
Field Details
-
UNSORTED
Unsorted singleton. 无排序单例。
-
-
Method Details
-
by
-
by
-
by
-
by
-
by
-
unsorted
-
getOrders
-
isUnsorted
public boolean isUnsorted() -
and
-
toSql
Renders this Sort as a SQL ORDER BY fragment (without theORDER BYkeyword). 渲染为 SQL ORDER BY 片段(不含ORDER BY关键字)。- Returns:
- SQL fragment, or empty string if unsorted | SQL 片段,无排序时为空字符串
-
toString
-
equals
-
hashCode
-