Simplifies the judgment of multiple if conditional statements, so that the judgment of multiple conditions query is simpler, no longer for the condition is empty and worry, here is only a template, specific examples also need to mediate their own
One: Create a list collection and load the list data
List listsql = new ArrayList ();
String sql = "";
Listsql.add ("Cxusers");
Listsql.add (txthphm==null "": TXTHPHM)//judge whether the resulting content is empty, empty will be marked as empty characters, on the other hand, is the foreground page passed the value of
listsql.add (txthpzl==null? ") : TXTHPZL);
Listsql.add (txtwfsjs==null "": TXTWFSJS);
Listsql.add (txtwfswje==null "": txtwfswje);
Listsql.add (zhxxcx==null "": ZHXXCX);//Comprehensive information Mark
Listsql.add (txtwfdd==null? "": TXTWFDD);//illegal location
mark Listsql.add (xq==null "": XQ);/district Mark
listsql.add (txetjdry==null? "": txetjdry);/Proofing Staff Mark
Two: Getzhxxsql method, used to execute conditional SQL statements
Public String getzhxxsql (List list) {//list StringBuffer sql = new StringBuffer (); if ("Cxusers". Equals (List.get (0). toString ())) {sql.append ("SELECT count (*) from nlv_violation t where 1=1 and T.JDZT =
' 2 ' and t.jllx= ' 1 '); if (List.size () >1) {if (! "").
Equals (List.get (1). ToString ())) {//If not NULL, executes this statement instead of Sql.append ("and t.hphm like '%" +list.get (1). ToString () + "%"); } if (List.size () >2) {if (!).
Equals (List.get (2). ToString ())) {Sql.append ("and T.hpzl= '" +list.get (2). ToString () + "'"); } if (List.size () >3) {if (!). Equals (List.get (3). ToString ())) {Sql.append ("and To_char (T.WFSJ, ' yyyy-mm-dd ') >= '" +list.get (3). ToString () + "'")
; } if (List.size () >4) {if (!). Equals (List.get (4). ToString ())) {Sql.append ("and To_char (T.WFSJ, ' yyyy-mm-dd ') <= '" +list.get (4). ToString () + "'")
; } if (List.size () >5) {if (!). Equals (List.get (5). toString ())) {Sql.append ("and t.sjly= '" +list.get (5). TostrING () + "'"); } if (List.size () >6) {if (!).
Equals (List.get (6). ToString ())) {Sql.append ("and t.wfdd like '%" +list.get (6). ToString () + "%"); } if (List.size () >7) {if (!).
Equals (List.get (7). ToString ())) {Sql.append ("and t.cjjg= '" +list.get (7). ToString () + "'"); } if (List.size () >8) {if (!).
Equals (List.get (8). ToString ())) {Sql.append ("and T.jdr= '" +list.get (8). ToString () + "'");
}} return sql.tostring (); }