出错总在不经意间 while===VS===if

Set> set = map.entrySet();
Set> set = (Set>) map.entrySet();
Iterator io = set.iterator();
Iterator> it = set.iterator();
while (io.hasNext()) {
Map.Entry me = (Map.Entry) io.next();
if ("username".equals(me.getKey()) && !"".equals(me.getValue())) {
sql.append( " and " + me.getKey() + " like '%" + me.getValue() + "%'");
}
if ("startTime".equals(me.getKey()) && !"".equals(me.getValue())) {
sql.append( " and " + me.getKey() + " >= '" + me.getValue() + "'");
}
if ("endTime".equals(me.getKey()) && !"".equals(me.getValue())) {
sql.append( " and " + me.getKey() + " <= '" + me.getValue() + "'");
}
/*if ("sort".equals(me.getKey()) && !"".equals(me.getValue())) {
sql.append( " order by " + me.getValue());
}
if ("order".equals(me.getKey()) && !"".equals(me.getValue())) {
sql.append( " " + me.getValue());
}*/
}




Set> set = (Set>) map.entrySet();
Iterator> it = set.iterator();
// System.out.println("it.size="+it.);
if (it.hasNext()) {
Entry entry = (Entry) it.next();
if ("username".equals(entry.getKey()) && !"".equals(entry.getValue())) {
sql.append(" and username like '%" + entry.getValue() + "%'");
}


if ("startTime".equals(entry.getKey()) && !"".equals(entry.getValue())) {
sql.append(" and startTime >= " + entry.getValue());
}


if ("endTime".equals(entry.getKey()) && !"".equals(entry.getValue())) {
sql.append(" and endTime <= " + entry.getValue());
}

* if ("startTime".equals(entry.getKey()) &&
* !"".equals(entry.getValue())) { sql.append(" and startTime >= " +
* entry.getValue()); }
 
}

你可能感兴趣的:(Java初级)