OrderUtil -排序工具

/**
* 排序工具
*
* @author vernon.chen
*
*/
public class OrderUtil {
/**
* 构建排序语句
*
* @param pageable
*            排序对象
* @return 排序语句
*/
public static StringBuffer buildOrderBy(Pageable pageable) {

StringBuffer orderBy = new StringBuffer("");

Iterator<Order> it = pageable.getSort().iterator();

if (null != it) {
if (it.hasNext()) {
orderBy.append(" ORDER BY ");
while (it.hasNext()) {
Order o = (Order) it.next();
String property = o.getProperty();
orderBy.append(property).append(" ").append(o.getDirection().name()).append(",");
}
orderBy.deleteCharAt(orderBy.length() - 1); // 删除最后的,
}
}

return orderBy;
}

/**
* 将前台传入的原始排序列名称映射到后台对应的实际列名称
*
* @param gridParams
*            入参
* @param columnOriginal
*            前台传入的原始列名称
* @param columnActual
*            后台对应的实际列名称
*/
public static void mappingOrderColumn(GridParams gridParams, String columnOriginal, String columnActual) {

String sortname = gridParams.getSortname();

if (columnOriginal.equals(sortname)) {
gridParams.setSortname(columnActual);
}
}
}

你可能感兴趣的:(order)