示例#1
0
 /**
  * 获取分页数据
  *
  * @param start
  * @param pagesize
  * @return
  * @throws SQLException sql异常
  */
 public List<NetWorkEntity> query(String name, PageInfo pageInfo) throws SQLException { // 查询所有
   StringBuilder queryQL = new StringBuilder("from NetWorkEntity  where 1=1 ");
   // 条件拼装列表
   List<String> paramNames = new ArrayList<String>();
   List<Object> paramValues = new ArrayList<Object>();
   // 名字
   if (!StringUtil.isBlank(name)) {
     queryQL.append(" and  name like :name ");
     paramNames.add("name");
     paramValues.add("%" + name + "%");
   }
   // 排序
   queryQL.append(" order by addTime asc");
   List<NetWorkEntity> resultSet =
       (List<NetWorkEntity>)
           pageQuery(
               queryQL.toString(),
               paramNames,
               paramValues,
               pageInfo.getStart(),
               pageInfo.getLimit());
   // 如果没有查到数据,并且当前页数大于1,就查找上一页数据,避免出现删除后没数据现象
   if (resultSet.size() == 0 && pageInfo.getNowPage() > 1) {
     pageInfo.setNowPage(pageInfo.getNowPage() - 1);
     resultSet =
         (List<NetWorkEntity>)
             pageQuery(
                 queryQL.toString(),
                 paramNames,
                 paramValues,
                 pageInfo.getStart(),
                 pageInfo.getLimit());
   }
   return resultSet;
 }
示例#2
0
 /**
  * 获取分页数据
  *
  * @return
  * @throws SQLException sql异常
  */
 public Integer getQueryCount(String name) throws SQLException {
   StringBuilder queryQL = new StringBuilder("select count(*) from NetWorkEntity where 1=1 ");
   // 条件拼装列表
   List<String> paramNames = new ArrayList<String>();
   List<Object> paramValues = new ArrayList<Object>();
   // 名字
   if (!StringUtil.isBlank(name)) {
     queryQL.append(" and  name like :name ");
     paramNames.add("name");
     paramValues.add("%" + name + "%");
   }
   return Integer.parseInt(
       uniqueResultObject(queryQL.toString(), paramNames, paramValues).toString());
 }