日期:2014-05-17 浏览次数:20689 次
/** * 获得分页(该方法暂时不支持sqlserver) * @param sql 查询数据数量的sql必须是select * from 开头 * @param args 参数列表(可以为null) * @param pageIndex 当前页数 * @param radix 分页的基数 * @param function 分页的js函数,比如:document.form1.submit() * @return PageModel * */ public PageModel getPage(String sql, Object[] args, int pageIndex, int radix, String function) { args = (null == args ? new Object[] {} : args); PageModel model = pagination(sql.replace("*", "count(*)"), args, pageIndex, radix, function); Object[] newArgs = new Object[args.length + 2]; for (int i = 0; i < args.length; i++) { newArgs[i] = args[i]; } if (JdbcConfig.DATABASE_ORACLE.equals(jdbcConfig.getDatabaseType())) { sql = "select * from ( select temp.*, rownum rownumt from (" + sql + ") temp where rownum <= ?) where rownumt > ?"; newArgs[newArgs.length - 2] = model.getStop(); newArgs[newArgs.length - 1] = model.getStart(); model.setList(getDataList(sql, newArgs)); } if (JdbcConfig.DATABASE_MYSQL.equals(jdbcConfig.getDatabaseType())) { sql += " limit ?,?"; newArgs[newArgs.length - 2] = model.getStart(); newArgs[newArgs.length - 1] = radix; model.setList(getDataList(sql, newArgs)); } return model; }
------解决方案--------------------
片段代码:
public PageModel getOrders(LogOrders orders, int pageIndex, int radix) { String sql = "select * from DECO_LOG_ORDERS where DEPT_NAME = ?"; List<Object> args = new ArrayList<Object>(); args.add(orders.getDeptName()); if (null != orders.getPactCode() && !"".equals(orders.getPactCode())) { sql += " and PACT_CODE like ?"; args.add("%" + orders.getPactCode() + "%"); } if (null != orders.getOrderCode() && !"".equals(orders.getOrderCode())) { sql += " and ORDER_CODE like ?"; args.add("%" + orders.getOrderCode() + "%"); } sql += " order by ORDERS_ID"; return getPage(sql, args.toArray(), pageIndex, radix, orders.getFunction()); }