/** * 自定义查询 * * @return * @throws Exception */ @RequestMapping(value = {"userDatagrid"}) @ResponseBody public Datagrid<User> userDatagrid( Long organId, String loginNameOrName, Integer page, Integer rows, String sort, String order) throws Exception { Page<User> p = userManager.getUsersByQuery(organId, loginNameOrName, page, rows, sort, order); Datagrid<User> dg = new Datagrid<User>(p.getTotalCount(), p.getResult()); return dg; }
/** * combogrid * * @return * @throws Exception */ @RequestMapping(value = {"combogrid"}) @ResponseBody public Datagrid<User> combogrid( @RequestParam(value = "ids", required = false) List<Long> ids, String loginNameOrName, Integer rows) throws Exception { Criterion statusCriterion = Restrictions.eq("status", StatusState.normal.getValue()); Criterion[] criterions = new Criterion[0]; criterions = (Criterion[]) ArrayUtils.add(criterions, 0, statusCriterion); Criterion criterion = null; if (Collections3.isNotEmpty(ids)) { // in条件 Criterion inCriterion = Restrictions.in("id", ids); if (StringUtils.isNotBlank(loginNameOrName)) { Criterion loginNameCriterion = Restrictions.like("loginName", loginNameOrName, MatchMode.ANYWHERE); Criterion nameCriterion = Restrictions.like("name", loginNameOrName, MatchMode.ANYWHERE); Criterion criterion1 = Restrictions.or(loginNameCriterion, nameCriterion); criterion = Restrictions.or(inCriterion, criterion1); } else { criterion = inCriterion; } // 合并查询条件 criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion); } else { if (StringUtils.isNotBlank(loginNameOrName)) { Criterion loginNameCriterion = Restrictions.like("loginName", loginNameOrName, MatchMode.ANYWHERE); Criterion nameCriterion = Restrictions.like("name", loginNameOrName, MatchMode.ANYWHERE); criterion = Restrictions.or(loginNameCriterion, nameCriterion); // 合并查询条件 criterions = (Criterion[]) ArrayUtils.add(criterions, 0, criterion); } } // 分页查询 Page<User> p = new Page<User>(rows); // 分页对象 p = userManager.findByCriteria(p, criterions); Datagrid<User> dg = new Datagrid<User>(p.getTotalCount(), p.getResult()); return dg; }