SpringDataJpa sort多参数排序

public class Station  {

    private String stationCode;// 站点编码
    private BigDecimal belongToDate;存款金额
}

import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;

public void test(){

    // 先按站点排序,同站点的按存款金额排序
    Sort sort = new Sort(Sort.Direction.DESC, "stationCode").and(new Sort(Sort.Direction.ASC, "belongToDate"));

    // 先按站点排序,同站点的按存款金额排序
    Order stationCodeOrder = new Order(Direction.DESC, "stationCode");
    Order belongToDateOrder = new Order(Direction.ASC, "belongToDate");
    List orders = new ArrayList();    
    orders.add(stationCodeOrder );//先按站点排序
    orders.add(belongToDateOrder );//再存款金额排序
    Sort sort2 = new Sort(orders);

    //先按站点排序,再存款金额排序
    Sort sort = new Sort(Direction.fromString("asc"), "stationCode", "belongToDate");
}

你可能感兴趣的:(SpringBoot相关,jpa,sort)