apache的stringutils工具提供了如何判断字符串是否为空的判断方法,我们可以借助它来进行一些字符串的操作
package cn.edu.nwsuaf.GYL.query.basedata;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import cn.edu.nwsuaf.GYL.query.BaseQuery;
public class DepartmentQuery extends BaseQuery {
private String name;
private String description;
@Override
public Map<String, Object> buildWhere() {
if(StringUtils.isNotBlank(this.name))
//判断那么属性是否为空,为空则返回假,不为空则返回真
{
this.getKeyValues().put("name", this.name);
}
if(StringUtils.isNotBlank(this.description))
{
this.getKeyValues().put("description", this.description);
}
return this.getKeyValues();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
其核心语句如下
@Override
public Map<String, Object> buildWhere() {
if(StringUtils.isNotBlank(this.name))
//判断那么属性是否为空,为空则返回假,不为空则返回真
{
this.getKeyValues().put("name", this.name);
}
if(StringUtils.isNotBlank(this.description))
{
this.getKeyValues().put("description", this.description);
}
return this.getKeyValues();
}