Because the length of the spliced sql statement is uncertain, it is decorated with StringBuffer instead of String.
string name = request . getparameter(" name ");
string address = request . getparemeter(" address ");
string buffer SQL = new string buffer();
SQL . append(" select * from Tuser as t where 1 = 1 ");
If (name! =null||! "".Equal to (name)) {
Sql.append ("and t.namelike"% "+name+"%");
}
If (address! =null||! "".Equal to (address)) {
Sql.append ("and t.addresslike"% "+address+"%");
}
The above is a concatenated sql statement, which means select * from Tuser as, where 1 = 1 will definitely be executed, and the last two will be executed according to user data parameters.
I wrote it by hand, not copied it, okay? Ask me if you don't know, and give points if you understand, hehe.