/**
* 获取列表总页数
*/
public static <T> int getListPages(List<T> list,int pageNum,int pageSize ){
if (isNull(list)){
return 0;
}
BaseQuery baseQuery=new BaseQuery();
baseQuery.setPageNum(pageNum);
baseQuery.setPageSize(pageSize);
//list的大小
int total = list.size();
baseQuery.setTotal(total);
return baseQuery.getPages();
} /**
* 对列表进行分页,索引左边包括,右边不包括
*/
public static <T> List<T> subListByPage(List<T> list,int pageNum,int pageSize ){
if (isNull(list)){
return Collections.emptyList();
}
BaseQuery baseQuery=new BaseQuery();
baseQuery.setPageNum(pageNum);
baseQuery.setPageSize(pageSize);
//list的大小
int total = list.size();
//对list进行截取
return list.subList(baseQuery.getStartPosition(),total-baseQuery.getStartPosition()>baseQuery.getPageSize()?baseQuery.getStartPosition()+baseQuery.getPageSize():total);
} /**
* 对列表进行索引截取,索引左边包括,右边不包括
*/
public static <T> List<T> subListByPosition(List<T> list,BaseQuery baseQuery){ if (isNull(list)){
baseQuery.setTotal(0);
return Collections.emptyList();
}
//设置列表总条数
int total = list.size();
baseQuery.setTotal(total); if ((baseQuery.getStartIndex()-1)>=total){
return Collections.emptyList();
}
//对list进行截取
return list.subList(baseQuery.getStartIndex()-1,baseQuery.getEndIndex()>total?total:baseQuery.getEndIndex());
} /**
*对列表字段进行比较排序
*/
public static <T> void sortByField(List<T> dtoList,String fieldName,String order) {
int compare=1;
if ("desc".equals(order)){
compare=-1;
}
int finalCompare = compare; Collections.sort(dtoList, new Comparator<T>() {
@Override
public int compare(T o1, T o2) {
PropertyDescriptor pd1 = null;
PropertyDescriptor pd2 = null;
Object value1 =null;
Object value2 =null;
try {
pd1 = new PropertyDescriptor(fieldName, o1.getClass());
value1 = pd1.getReadMethod().invoke(o1, null); pd2 = new PropertyDescriptor(fieldName, o2.getClass());
value2 = pd2.getReadMethod().invoke(o2, null); } catch (IntrospectionException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} if (value1.getClass().equals(Double.class)){
System.out.println(2);
if ((Double)value1 > (Double)value2) {
return finalCompare;
} else if ((Double)value1 < (Double)value2) {
return -finalCompare;
}
}else if (value1.getClass().equals(Integer.class)){
System.out.println(4);
if ((Integer)value1 > (Integer)value2) {
return finalCompare;
} else if ((Integer)value1 < (Integer)value2) {
return -finalCompare;
}
}
return 0;
}
});
}

最新文章

  1. java中的IO操作
  2. C#整数三种强制类型转换int、Convert.ToInt32()、int.Parse()的区别
  3. 深入学习golang(1)—数组与切片
  4. Win7下:编译器错误信息: CS0016: 未能写入输出文件
  5. Save ITCM
  6. .net序列化和反系列化json与类型对象转换
  7. Oracle11g R2学习系列 之三教程选择
  8. string 与wstring 的转换
  9. Nginx安装及配置虚拟主机
  10. EJB系列 - EJB高级概念
  11. if处理多分支结构
  12. 如何高逼格读取Web.config中的AppSettings
  13. memcached实战系列(三)memcached命令使用
  14. FCN网络
  15. YIT-CTF—隐写术
  16. echo变量失败,提示:ECHO 处于关闭状态
  17. CentOS7 使用ntp设置系统时间,开机自动设置时间,
  18. 令新手头疼的modelsim库编译
  19. MySQL IFNULL()函数用法MySQL
  20. 虚拟机使用主机ss代理

热门文章

  1. &quot;AssertionError: View function mapping is overwriting an existing endpoint function&quot;如何解决
  2. Git学习总结(12)——多人开发 Git 分支管理详解
  3. netstat命令介绍-要用熟
  4. 不错的题目-n个数连接得到的最大值
  5. HDU 4507
  6. 错误总结之播放器(vitamio)音量实体键与触摸手势控制,音量调节冲突
  7. Codeforces Round #313 (Div. 2) 560D Equivalent Strings(dos)
  8. 学习日记之原型模式和Effective C++
  9. UVa 11722(几何概率)
  10. CodeForces--621A--Wet Shark and Odd and Even(数学水题)