我的代码出了问题。如果我输入了正确的标准,那就说300它返回正确的结果数量。但是如果我没有合格的搜索条件,它仍然会返回不正确的结果。
@Override
public Page<ApPayment> searchPayment(final String searchCriteria,
final PageSetting pageSetting) {
HibernateCallback<Page<ApPayment>> paymentCallBack = new HibernateCallback<Page<ApPayment>>() {
@Override
public Page<ApPayment> doInHibernate(Session session)
throws HibernateException, SQLException {
Criteria criteria = session.createCriteria(ApPayment.class);
if(!searchCriteria.isEmpty() && StringFormatUtil.isNumeric(searchCriteria)) {
Integer paymentNo = Integer.valueOf(searchCriteria);
Double amount = Double.valueOf(searchCriteria);
criteria.add(Restrictions.or(Restrictions.like(ApPayment.FIELD.paymentNumber.name(), paymentNo), Restrictions.eq(ApPayment.FIELD.amount.name(), amount)));
}
Page<ApPayment> payments = getAll(criteria, pageSetting);
for (ApPayment payment: payments.getData()) {
--some codes--
}
return payments;
}
};
return getHibernateTemplate().execute(paymentCallBack);
}
提前致谢。