判断问题?
下面是我的一个查询方法(多条件查询):
System.out.println("0000000000");能够打印,到了if判断里,就不能打印了,为什么进不了if判断呢?不知道错误在哪?
其中StringUtil.isEmpty是一个判断不为空的方法(方法可以用),这里调用了。我用的struts2 ,hebinate3,和DAO模式开发。
//根据条件查询
public ForShipmentModel queryby(Session sess, ForShipmentModel model) {
try{
StringBuffer sb = new StringBuffer("from ForShipmentModel orderinfo where orderinfo.id=:id ");
boolean flag = false;
System.out.println("0000000000");
if (!StringUtil.isEmpty(model.getApplyPersonName()))
{
System.out.println("11111111111111");
sb.append(" orderinfo.applyPersonName = " + model.getApplyPersonName());
flag = true;
}
if (!StringUtil.isEmpty(model.getOrderNumber()))
{
if (flag == true)
{
sb.append(" and orderinfo.orderNumber = " + model.getOrderNumber());
}else
{
sb.append(" orderinfo.orderNumber = " + model.getOrderNumber());
flag = true;
}
}
if (!StringUtil.isEmpty(model.getCustomer()))
{
if (flag == true)
{
sb.append(" and orderinfo.customer = " + model.getCustomer());
}else
{
sb.append(" orderinfo.customer = " + model.getCustomer());
flag = true;
}
}
if (model.getApproveState() > 0)
{
if (flag == true)
{
sb.append("and orderinfo.approveState = " + model.getApproveState());
}else
{
sb.append("orderinfo.approveState = " + model.getApproveState());
flag = true;
}
}
if (model.getOrderDate() != null)
{
if (flag == true)
{
sb.append(" and orderinfo.orderStatus = " + model.getOrderDate());
}else
{
sb.append(" orderinfo.orderStatus = " + model.getOrderDate());
flag = true;
}
}
if (flag == true)
{
Query qCount = sess.createQuery("select count(*) "
+ sb.toString());
int totalNum = ((Integer) qCount.iterate().next()).intValue();
model.setRecordCount(totalNum);
sb.append(" order by orderinfo.id");
System.out.println(qCount);
// 加分页的
Query q = sess.createQuery(sb.toString());
q.setFirstResult(model.getPageSize() * (model.getPageNo() - 1));
q.setMaxResults(model.getPageSize());
List list = q.list();
model.setModelList(list);
}
System.out.println("3333");
return model;
}
catch(Exception e){
System.out.println("---------File: ForShipmentDaoImpl.java ==== Method:Queryby() -------------");
e.printStackTrace();
return null;
}
}
------解决方案--------------------
------解决方案--------------------只能说明model.getApplyPersonName()为空了
------解决方案--------------------代码太乱了,为什么不用代码格式。
------解决方案--------------------debug
------解决方案--------------------在用 if (!StringUtil.isEmpty(model.getApplyPersonName())) 之前
先用System.out.println(model.getApplyPersonName());看这个值是不是为空.
------解决方案--------------------那就证明你的参数传递有问题被!
那就不是你贴的代码能看出来的
检查下model在那里获得的?