The data obtained from the database is generally returned in an entity manner. But to make a statement, it may be from the entity of a property to show that the so-called column inversion. So someone wrote a list of inverted SQL, and here's a Java implementation example. Attributes are written to death. If you need to be flexible, replace it with reflection to traverse the property.
/** * The list information ranks inverted */package jdk_1_4.test; Import java.util.ArrayList; Import java.util.Collections; Import Java.util.Comparator; Import Java.util.Iterator; Import Java.util.LinkedHashMap; Import java.util.LinkedList; Import java.util.List; Import Java.util.Map; public class V2htest {/** * @param args */public static void main (string[] args) {List dataList = new ArrayList (); setd ATA (DataList, "1"); SetData (DataList, "2"); --Sort Collections.sort by date and brand (DataList, new Comparator () {public int compare (object O1, Object O2) {Datamodel dm1 = (Da Tamodel) O1; Datamodel dm2 = (datamodel) O2; int flag = Dm1.getdate (). CompareTo (Dm2.getdate ()); if (flag = = 0) {flag = Dm1.gettobacconame (). CompareTo (Dm2.gettobacconame ());} return flag; } }); /**/System.out.println ("--------------------------------------before the rank and column conversion"); for (int i=0;i<datalist.size (); i++) {datamodel dm = (datamodel) datalist.get (i); System.out.println ("Date:" +dm.getdate ()); System.out.println ("Cigarette:" +dm.gettobacconame ()); System.out.prIntln (Dm.getdate () + "Day production Plan:" +dm.getproduceqty ()); System.out.println (Dm.getdate () + "Day sales Plan:" +dm.getsaleqty ()); System.out.println (Dm.getdate () + "Daily Minimum inventory line:" +dm.getinvlinelow ()); System.out.println (Dm.getdate () + "Day of the highest inventory line:" +dm.getinvlinehigh ()); System.out.println (Dm.getdate () + "Day at the end of inventory:" +dm.getinventoryqty ()); SYSTEM.OUT.PRINTLN ("----"); //--row inversion Map v2hmap = new Linkedhashmap (); V2hmap = v2h (datalist,6); Object[] Tobaccoarr = (object[]) v2hmap.get ("Tobacco"); System.out.println ("--------------------------------------/n" After the order of rows); System.out.println ("-------cigarette brand"); System.out.print (""); for (int i=0;i<tobaccoarr.length;i++) {System.out.print (tobaccoarr[i]+ "");} System.out.println (); V2hmap.remove ("Tobacco"); /**/Iterator it = V2hmap.keyset (). iterator (); while (It.hasnext ()) {String key = It.next (). toString ();//system.out.println (key);/**/LinkedList hlist = (linkedlist) v 2hmap.get (key); for (int i=0;i