Struts2中list排序 sort标签按降序排列

struts2中sort标签默认是按升序排列的,如果想按降序排列按照以下方法即可。

  <s:bean id="myComparator" name="com.tfyy.yx.util.system.MyComparator"></s:bean>
  <s:sort comparator="myComparator" source="budget.approve">
  	<s:iterator value="budget.approve" status="st"> </s:iterator>
 </s:sort>

 

 

package com.tfyy.yx.util.system;

import java.util.Comparator;

public class MyComparator implements Comparator<Object> {
	public int compare(Object arg0, Object arg1) {

		   System.out.println(arg0.toString().compareTo(arg1.toString()));

		  //默认从小到大排列
		   return arg0.toString().compareTo(arg1.toString());    

		   //从大到小排列
		   //return -(arg0.toString().compareTo(arg1.toString()));    

		}


}

  

你可能感兴趣的:(struts2)