我正在对server-side
实施dataTable
过滤。在实现过滤的服务中,我想测试search
条件是number
;如果是,那么我实现基于类型double
(工资)的bean属性的过滤,否则我根据String(用户名)类型的bean属性进行过滤:
@Override
@Transactional
public List<User> list(int start, int length, String search) {
Criteria criteres = sessionFactory.getCurrentSession().createCriteria(User.class);
if (!search.equals("")) {
if (NumberUtils.isNumber(search))
criteres.add(Restrictions.like("salary", Double.parseDouble(search)));
else
criteres.add(Restrictions.like("username", search, MatchMode.ANYWHERE));
}
criteres.setFirstResult(start);
criteres.setMaxResults(length);
criteres.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
@SuppressWarnings("unchecked")
List<User> listUser = (List<User>) criteres.list();
return listUser;
}
问题在于,如果我写:
if (!search.equals("")) {
if (NumberUtils.isNumber(search))
criteres.add(Restrictions.like("salary", String.valueOf(Double.parseDouble(search)), MatchMode.ANYWHERE));
else
criteres.add(Restrictions.like("username", search, MatchMode.ANYWHERE));
}
然后我收到警告错误:DataTables warning: table id=t_list - Ajax error. For more information about this error, please see http://datatables.net/tn/7
那么如何才能在double
变量上创建“ like ”条件?