SQL statement and SQL statement
1 StringBuilder SQL = new StringBuilder ("SELECT * FROM t_customer WHERE 1 = 1"); 2/* 3*2. determine the condition to complete the append of the where clause 4 */5/* 6*3 to the SQL statement. create an ArrayList to load the parameter value 7 */8 List <Object> params = new ArrayList <Object> (); 9 String cname = criteria. getCname (); 10 if (cname! = Null &&! Cname. trim (). isEmpty () {11 SQL. append ("and cname like? "); 12 params. add (" % "+ cname +" % "); 13} 14 15 String gender = criteria. getGender (); 16 if (gender! = Null &&! Gender. trim (). isEmpty () {17 SQL. append ("and gender =? "); 18 params. add (gender); 19} 20 21 String cellphone = criteria. getCellphone (); 22 if (cellphone! = Null &&! Cellphone. trim (). isEmpty () {23 SQL. append ("and cellphone like? "); 24 params. add (" % "+ cellphone +" % "); 25} 26 27 String email = criteria. getEmail (); 28 if (email! = Null &&! Email. trim (). isEmpty () {29 SQL. append ("and email like? "); 30 params. add (" % "+ email +" % "); 31}