看似不重要的一句话其实可以省略好多代码
例如String sql=" select * from student where 1=1";
if (name!=null) sql+="and name like "%%"";
if (age!=null) sql+="and age like "%%"";
如果没有使用where 1=1;
String sql=" select * from student";
if (name!=null) sql+="where name like "%%"";
if(name==null and age!=null) sql+="where age like "%%"";
if (age!=null) sql+="and age like "%%"";
两个字段的非空可能都要判断的,逻辑思维比较杂乱,所以用上where 1=1 就可以解决很多问题的。