最好用的分页代码(java版)(10)

发布时间:2021-06-05

log.error(">sql 无效:" + sql); return 0; } if (where == null) where = ""; try { String fromTrim = from.substring(from.indexOf("from")); String s = "select count(1) " + fromTrim + " " + where; log.debug("get total count sql:" + s); return getSpringJdbcTemplate().queryForInt(s); } catch (Exception e) { e.printStackTrace(); return 0; } } /** * 通过sql查询一页的数据 * * @param sql * @param firstResult * @param maxResults * @return */ private List getPageData(final String sql, final int firstResult, final int maxResults) { log.debug("$$sql=" + sql + "; firstResult=" + firstResult + "; maxResults=" + maxResults); try { JdbcTemplate jt = getSpringJdbcTemplate(); return queryForList(sql + " limit " + firstResult + "," + maxResults, jt); } catch (Exception e) { e.printStackTrace(); } return new ArrayList(); } public static List queryForList(String sql, JdbcTemplate jt) { log.debug("SpringJdbcTemplate:" + sql); final List list = new ArrayList(); try { jt.query(sql, new RowCallbackHandler() { public void processRow(ResultSet rs) throws SQLException { HashMap m = new HashMap();

精彩图片

热门精选

大家正在看