diff --git a/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java b/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java index 1d416b8f..a7faaf6d 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java @@ -924,13 +924,24 @@ public class ResourceController { if (params.containsKey("page") && org.apache.commons.lang3.StringUtils.isNotBlank(params.get("page").toString())) { page = Integer.parseInt(params.get("page").toString()); } - String sql = String.format("SELECT * FROM policy_cloud_service LIMIT %d,%d", (page - 1) * pageSize, pageSize); - long count = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM policy_cloud_service", Long.class); + String sql; + String sqlRoot = "SELECT * FROM policy_cloud_service "; + String where = " WHERE 1=1 "; + String limit = String.format(" LIMIT %d,%d", (page - 1) * pageSize, pageSize); + + long count = 0; + if (params.containsKey("name") && org.apache.commons.lang3.StringUtils.isNotBlank(params.get("name").toString())) { - sql = String.format("SELECT * FROM policy_cloud_service WHERE service_description LIKE '%s' LIMIT %d,%d", "%" + params.get("name").toString() + "%", (page - 1) * pageSize, pageSize); - count = jdbcTemplate.queryForObject(String.format("SELECT COUNT(*) FROM policy_cloud_service WHERE service_description LIKE '%s'", "%" + params.get("name").toString() + "%"), Long.class); + where = where + String.format(" AND service_description LIKE '%s'", "%" + params.get("name").toString() + "%"); } + if (params.containsKey("type") && org.apache.commons.lang3.StringUtils.isNotBlank(params.get("type").toString())) { + where = where + String.format(" AND service_type = '%s'", params.get("type").toString()); + } + + sql = sqlRoot + where + limit; logger.info("sql:" + sql); + String sqlCount = "SELECT COUNT(*) FROM policy_cloud_service " + where; + count = jdbcTemplate.queryForObject(sqlCount, Long.class); List> result = jdbcTemplate.queryForList(sql); return new Result>>().ok(new PageData<>(result, count)); }