最好用的分页代码(java版)(10)
发布时间:2021-06-05
发布时间: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();
上一篇:四级完形精选练习及答案(26)
下一篇:桑黄胞外多糖药理活性的初步研究