List根据对象的某个属性排序工具类 List排序importjava.util.Collections;importjava.util.Comparator;importjava.util.List;importorg.apache.commons.beanutils.BeanComparator;importorg.apache.commons.collections.ComparatorUtils;importorg.apache.commons.collections.comparators.ComparableComparator;public classListSortUtil {/*** 按bean的属性值对list集合进行排序 
*
*
@paramlist
* 要排序的集合
*
@parampropertyName
* 集合元素的属性名
*
@paramisAsc
* 排序方向,true--正向排序,false--逆向排序
*
@return排序后的集合*/ public static List sortList(List list, String propertyName, booleanisAsc) {//借助commons-collections包的ComparatorUtils//BeanComparator,ComparableComparator和ComparatorChain都是实现了Comparator这个接口 if(list!=null && list.size()>0){
Comparator mycmp
=ComparableComparator.getInstance();
mycmp
= ComparatorUtils.nullLowComparator(mycmp); //允许null if(isAsc){
mycmp
= ComparatorUtils.reversedComparator(mycmp); //逆序 }
Comparator cmp
= newBeanComparator(propertyName, mycmp);
Collections.sort(list, cmp);
}
returnlist;
}
}

 

img如果没有图片显示默认图片效果
<img src="本来要显示的图片URL" onerror="this.src='图片挂了的话要显示的默认图片URL'" />
其实就是说,在这个img的行为失败(onerror)的时候,调用javascript:
this.src="URL"
来给这个img标签重新指定src属性,从而达到显示备用图片的效果。

免责声明
本博客部分内容来自于互联网,不代表作者的观点和立场,如若侵犯到您的权益,请联系[email protected]。我们会在24小时内进行删除。