如何通过降序排序并获取最大结果,最后我希望列表按升序排序。我有以下代码无效
Criteria cr = sessionFactory.getCurrentSession().createCriteria(Employee.class)
.add(Restrictions.eq("empId", empId)).add(Restrictions.eq("empCode", empCode));
cr.addOrder(Order.desc("joinDate"));
cr.setMaxResults(5);
cr.addOrder(Order.asc("joinDate"));
return cr.list();
答案 0 :(得分:1)
noOfEmployee是您应该初始化的上述标准的列表返回,而Employee是模型类。
Collections.sort(noOfEmployee, new Comparator<Employee>(){
@Override
public int compare(Employee o1, Employee o2) {
// TODO Auto-generated method stub
return o1.getJoinDate().compareTo(o2.getJoinDate());
}
});