
cn.cucc.bean.Sort Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jpaHelper Show documentation
Show all versions of jpaHelper Show documentation
spring-data-jpa增强工具包,简化 CRUD 操作
package cn.cucc.bean;
import java.util.ArrayList;
import java.util.List;
import cn.cucc.bean.OrderBy.Direction;
import cn.cucc.reflection.ReflectionUtil;
import cn.cucc.reflection.SerializableFunction;
import cn.hutool.core.util.StrUtil;
public class Sort {
List orderList = new ArrayList<>();
public Sort() {
}
public Sort(String column, Direction direction) {
OrderBy order = new OrderBy();
order.setColumn(column);
order.setDirection(direction);
orderList.add(order);
}
public Sort(List orderList) {
this.orderList.addAll(orderList);
}
public Sort(SerializableFunction column, Direction direction) {
OrderBy order = new OrderBy();
order.setColumn(ReflectionUtil.getFieldName(column));
order.setDirection(direction);
orderList.add(order);
}
public Sort add(String column, Direction direction) {
OrderBy order = new OrderBy();
order.setColumn(column);
order.setDirection(direction);
orderList.add(order);
return this;
}
public Sort add(SerializableFunction column, Direction direction) {
OrderBy order = new OrderBy();
order.setColumn(ReflectionUtil.getFieldName(column));
order.setDirection(direction);
orderList.add(order);
return this;
}
public String toString() {
List sqlList = new ArrayList<>();
for (OrderBy order : orderList) {
String sql = "`" + StrUtil.toUnderlineCase(order.getColumn()) + "`";
if (order.getDirection() == Direction.ASC) {
sql += " ASC";
}
if (order.getDirection() == Direction.DESC) {
sql += " DESC";
}
sqlList.add(sql);
}
if (sqlList.size() > 0) {
return " ORDER BY " + StrUtil.join(",", sqlList);
} else {
return "";
}
}
public List getOrderList() {
return orderList;
}
public void setOrderList(List orderList) {
this.orderList = orderList;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy