我有一个打印用户的用户界面,我不想按国家过滤。 我做了一个经典的<select />
元素。如何处理<select> HTML过滤器中的空值?
在JSP中我有
<select id="country" onchange="return filter();">
<option value="">...</option>
<c:forEach var="country" items="${countries}">
<option value="${country.id}"
${country.name}
</option>
</c:forEach>
</select>
的东西是一些用户没有一个国家,所以我需要处理2个过滤器: - 一个打印所有用户,没有过滤 - 一个只打印没有国家的用户
所以我想知道对Java说最好的方法是什么:“找到我所有的用户”和“找到我没有的所有用户国家”。
我有一些想法:如果countryId = 0,则服务器翻译为所有用户“谁没有一个国家,如果countryId = null,则服务器翻译为用户‘’
。最后,DAO对象会做出这样
public List<User> findByCountry(Integer countryId){
query = "select * from users"
if(countryId==0){
query+= " where country_id is null"
}
else if(countryId==null){
query += " where country_id = " + countryId;
}
return query results...
}
查询所以这是正确的,或者是这个丑陋的,或者有人有更好的方式来做到这一点?