|
42 | 42 | import javax.servlet.http.HttpServletResponse;
|
43 | 43 | import java.io.File;
|
44 | 44 | import java.io.IOException;
|
| 45 | +import java.math.BigDecimal; |
| 46 | +import java.math.BigInteger; |
45 | 47 | import java.util.ArrayList;
|
46 | 48 | import java.util.List;
|
47 | 49 | import java.util.Map;
|
@@ -75,19 +77,22 @@ public Object getTables(String name, int[] startEnd) {
|
75 | 77 | // 使用预编译防止sql注入
|
76 | 78 | String sql = "select table_name ,create_time , engine, table_collation, table_comment from information_schema.tables " +
|
77 | 79 | "where table_schema = (select database()) " +
|
78 |
| - "and table_name like ? order by create_time desc"; |
| 80 | + "and table_name like :table order by create_time desc"; |
79 | 81 | Query query = em.createNativeQuery(sql);
|
80 | 82 | query.setFirstResult(startEnd[0]);
|
81 | 83 | query.setMaxResults(startEnd[1] - startEnd[0]);
|
82 |
| - query.setParameter(1, StringUtils.isNotBlank(name) ? ("%" + name + "%") : "%%"); |
| 84 | + query.setParameter("table", StringUtils.isNotBlank(name) ? ("%" + name + "%") : "%%"); |
83 | 85 | List result = query.getResultList();
|
84 | 86 | List<TableInfo> tableInfos = new ArrayList<>();
|
85 | 87 | for (Object obj : result) {
|
86 | 88 | Object[] arr = (Object[]) obj;
|
87 | 89 | tableInfos.add(new TableInfo(arr[0], arr[1], arr[2], arr[3], ObjectUtil.isNotEmpty(arr[4]) ? arr[4] : "-"));
|
88 | 90 | }
|
89 |
| - Query query1 = em.createNativeQuery("SELECT COUNT(*) from information_schema.tables where table_schema = (select database())"); |
90 |
| - Object totalElements = query1.getSingleResult(); |
| 91 | + String countSql = "select count(1) from information_schema.tables " + |
| 92 | + "where table_schema = (select database()) and table_name like :table"; |
| 93 | + Query queryCount = em.createNativeQuery(countSql); |
| 94 | + queryCount.setParameter("table", StringUtils.isNotBlank(name) ? ("%" + name + "%") : "%%"); |
| 95 | + Object totalElements = queryCount.getSingleResult(); |
91 | 96 | return PageUtil.toPage(tableInfos, totalElements);
|
92 | 97 | }
|
93 | 98 |
|
|
0 commit comments