Commit 120b37cda4708a00dae21fdff7253f3033e11f92
1 parent
35e87a65
Exists in
master
and in
2 other branches
fix a bug about page util
Showing
3 changed files
with
15 additions
and
38 deletions
Show diff stats
build.gradle
src/main/java/com/taover/repository/CustomJdbcTemplate.java
... | ... | @@ -371,14 +371,8 @@ public class CustomJdbcTemplate<T, ID extends Serializable> { |
371 | 371 | String pageSql = sql.toString() + " limit ?, ?"; |
372 | 372 | |
373 | 373 | Map<String, Object> totalRowsMap = (fromWriteDB ? jdbcTemplateWrite : jdbcTemplateRead).queryForMap(sqlCount.toString(), count_list.toArray()) ; |
374 | - | |
375 | - Map<String, Object> resultMap = new HashMap<String, Object>(); | |
376 | - resultMap.put("page", page); | |
377 | - resultMap.put("total", totalRowsMap.get("rowCount")); | |
378 | - List<T> resultList = null; | |
379 | - resultList = (fromWriteDB ? jdbcTemplateWrite : jdbcTemplateRead).query(pageSql.toString(), this.customJdbcTemplateRowMapper, page_list.toArray()); | |
380 | - resultMap.put("rows", resultList); | |
381 | - return resultMap; | |
374 | + List<T> resultList = (fromWriteDB ? jdbcTemplateWrite : jdbcTemplateRead).query(pageSql.toString(), this.customJdbcTemplateRowMapper, page_list.toArray()); | |
375 | + return UtilsSql.createPage(page, pageSize, Integer.valueOf(totalRowsMap.get("rowCount").toString()), resultList); | |
382 | 376 | } |
383 | 377 | |
384 | 378 | /** |
... | ... | @@ -401,14 +395,8 @@ public class CustomJdbcTemplate<T, ID extends Serializable> { |
401 | 395 | page_list.add(page * pageSize); |
402 | 396 | |
403 | 397 | Map<String, Object> totalRowsMap = (fromWriteDB ? jdbcTemplateWrite : jdbcTemplateRead).queryForMap(sqlCount.toString()); |
404 | - | |
405 | - Map<String, Object> resultMap = new HashMap<String, Object>(); | |
406 | - resultMap.put("page", page); | |
407 | - resultMap.put("total", totalRowsMap.get("rowCount")); | |
408 | - List<T> resultList = null; | |
409 | - resultList = (fromWriteDB ? jdbcTemplateWrite : jdbcTemplateRead).query(pageSql.toString(), this.customJdbcTemplateRowMapper, page_list.toArray()); | |
410 | - resultMap.put("rows", resultList); | |
411 | - return resultMap; | |
398 | + List<T> resultList =(fromWriteDB ? jdbcTemplateWrite : jdbcTemplateRead).query(pageSql.toString(), this.customJdbcTemplateRowMapper, page_list.toArray()); | |
399 | + return UtilsSql.createPage(page, pageSize, Integer.valueOf(totalRowsMap.get("rowCount").toString()), resultList); | |
412 | 400 | } |
413 | 401 | |
414 | 402 | /** |
... | ... | @@ -624,7 +612,7 @@ public class CustomJdbcTemplate<T, ID extends Serializable> { |
624 | 612 | Map<String, Object> countData = new HashMap<String, Object>(); |
625 | 613 | queryData = this.jdbcTemplateRead.queryForList(querySql); |
626 | 614 | countData = this.jdbcTemplateRead.queryForMap(countSql); |
627 | - return UtilsSql.createPage(page, Integer.valueOf(countData.get("rows").toString()), queryData); | |
615 | + return UtilsSql.createPage(page, pageSize, Integer.valueOf(countData.get("rows").toString()), queryData); | |
628 | 616 | } |
629 | 617 | |
630 | 618 | public <E> Map<String, Object> getBeanPageData(String coreSql, String orderByPartSql, Integer page, Integer pageSize, Class<E> beanClass){ |
... | ... | @@ -639,7 +627,7 @@ public class CustomJdbcTemplate<T, ID extends Serializable> { |
639 | 627 | Map<String, Object> countData = new HashMap<String, Object>(); |
640 | 628 | queryData = this.jdbcTemplateRead.queryForList(querySql, beanClass); |
641 | 629 | countData = this.jdbcTemplateRead.queryForMap(countSql); |
642 | - return UtilsSql.createPage(page, Integer.valueOf(countData.get("rows").toString()), queryData); | |
630 | + return UtilsSql.createPage(page, pageSize, Integer.valueOf(countData.get("rows").toString()), queryData); | |
643 | 631 | } |
644 | 632 | |
645 | 633 | /** |
... | ... | @@ -781,14 +769,8 @@ public class CustomJdbcTemplate<T, ID extends Serializable> { |
781 | 769 | String pageSql = sql.toString() + " limit ?, ?"; |
782 | 770 | |
783 | 771 | Map<String, Object> totalRowsMap = (fromWriteDB ? jdbcTemplateWrite : jdbcTemplateRead).queryForMap(sqlCount.toString(), count_list.toArray()) ; |
784 | - | |
785 | - Map<String, Object> resultMap = new HashMap<String, Object>(); | |
786 | - resultMap.put("page", page); | |
787 | - resultMap.put("total", totalRowsMap.get("rowCount")); | |
788 | - List<E> resultList = null; | |
789 | - resultList = (fromWriteDB ? jdbcTemplateWrite : jdbcTemplateRead).query(pageSql.toString(), new CustomJdbcTemplateRowMapper(beanClass, this.tableToBeanField), page_list.toArray()); | |
790 | - resultMap.put("rows", resultList); | |
791 | - return resultMap; | |
772 | + List<E> resultList = (fromWriteDB ? jdbcTemplateWrite : jdbcTemplateRead).query(pageSql.toString(), new CustomJdbcTemplateRowMapper(beanClass, this.tableToBeanField), page_list.toArray()); | |
773 | + return UtilsSql.createPage(page, pageSize, Integer.valueOf(totalRowsMap.get("rowCount").toString()), resultList); | |
792 | 774 | } |
793 | 775 | |
794 | 776 | /** |
... | ... | @@ -811,13 +793,7 @@ public class CustomJdbcTemplate<T, ID extends Serializable> { |
811 | 793 | page_list.add(page * pageSize); |
812 | 794 | |
813 | 795 | Map<String, Object> totalRowsMap = (fromWriteDB ? jdbcTemplateWrite : jdbcTemplateRead).queryForMap(sqlCount.toString()); |
814 | - | |
815 | - Map<String, Object> resultMap = new HashMap<String, Object>(); | |
816 | - resultMap.put("page", page); | |
817 | - resultMap.put("total", totalRowsMap.get("rowCount")); | |
818 | - List<E> resultList = null; | |
819 | - resultList = (fromWriteDB ? jdbcTemplateWrite : jdbcTemplateRead).query(pageSql.toString(), new CustomJdbcTemplateRowMapper(beanClass, this.tableToBeanField), page_list.toArray()); | |
820 | - resultMap.put("rows", resultList); | |
821 | - return resultMap; | |
796 | + List<E> resultList = (fromWriteDB ? jdbcTemplateWrite : jdbcTemplateRead).query(pageSql.toString(), new CustomJdbcTemplateRowMapper(beanClass, this.tableToBeanField), page_list.toArray()); | |
797 | + return UtilsSql.createPage(page, pageSize, Integer.valueOf(totalRowsMap.get("rowCount").toString()), resultList); | |
822 | 798 | } |
823 | 799 | } | ... | ... |
src/main/java/com/taover/repository/UtilsSql.java
... | ... | @@ -76,11 +76,12 @@ public class UtilsSql { |
76 | 76 | * @param data |
77 | 77 | * @return |
78 | 78 | */ |
79 | - public static Map<String, Object> createPage(int page, int rows, Object data){ | |
79 | + public static Map<String, Object> createPage(int page, int size, int total, Object data){ | |
80 | 80 | Map<String, Object> pageData = new HashMap<String, Object>(); |
81 | 81 | pageData.put("page", page); |
82 | - pageData.put("rows", rows); | |
83 | - pageData.put("data", data); | |
82 | + pageData.put("rows", data); | |
83 | + pageData.put("size", size); | |
84 | + pageData.put("total", total); | |
84 | 85 | return pageData; |
85 | 86 | } |
86 | 87 | } | ... | ... |