在多条件模糊查询的时候,如何确定SQL语句(实战技巧)
如图,在这"businessAddress like '%"+businessAddress+"%'"
句之前是否需要加and?
解决:利用永真式1=1
String sql = "select * from business where 1=1 ";
if (businessName!=null&&!businessName.equals("")){//判断字符串是否为空
sql += "and businessName like '%"+businessName+"%'";
}
if (businessAddress!=null&&!businessAddress.equals("")){//判断字符串是否为空
sql += "and businessAddress like '%"+businessAddress+"%'";
}