Scenario: assume there are two table request information and account tables, which are one-to-many relationships. The corresponding java classes are Sfcx_RequestInfo and Sfcx_Zhxx. Sfcx_RequestInfo has a Set attribute sfcx_Zhxxs. You need to sort Sfcx_Zhxx by the account information query sequence number (ccxh. Solution: 1: configure the account information comparison auxiliary class. You can also define internal classes or write them to Sfcx_RequestInfo. Implement the Comparator interface. Override the compare method. Specify the configuration rules in this method.
package com.levelappro.gbism.app.sfcx.model; import java.util.Comparator; public class ComparatorZhxx implements Comparator<Sfcx_Zhxx> { public int compare(Sfcx_Zhxx z1, Sfcx_Zhxx z2) { if(z1.getCcxh().compareTo(z2.getCcxh())>0) return 1; if(z1.getCcxh().compareTo(z2.getCcxh())<0) return -1; return 0; } }
2: define a new get method getSfcx_ZhxxsTreeSet on one side (Sfcx_RequestInfo) to deploy the sorted TreeSet.
/*** Get an ordered set of account information, sorted by the query Sequence Number * @ return */public TreeSet <Sfcx_Zhxx> getSfcx_ZhxxsTreeSet () {TreeSet <Sfcx_Zhxx> zhxxTreeSet = new TreeSet <Sfcx_Zhxx> (new ComparatorZhxx (); zhxxTreeSet. addAll (sfcx_Zhxxs); return zhxxTreeSet ;}
3: Call getSfcx_ZhxxsTreeSet to obtain the set of TreeSet.
for(Sfcx_RequestInfo info :infos){ TreeSet<Sfcx_Zhxx> zhxxSet = info.getSfcx_ZhxxsTreeSet();