Example #1
0
  /**
   * 根据某个条件分页查询数据
   *
   * @param <T>
   * @param c 查询的表
   * @param fieldName 匹配字段名
   * @param value 匹配的值
   * @param currentPage 当前页码
   * @param pageSize 每页数据量
   * @return List
   */
  public <T> List<T> searchByPage(
      Class<T> c, String fieldName, String value, int currentPage, int pageSize) {

    Entity<T> entity = dao.getEntity(c);

    String column = entity.getField(fieldName).getColumnName();

    Pager pager = dao.createPager(currentPage, pageSize);

    return dao.query(c, Cnd.where(column, "=", value), pager);
  }
Example #2
0
 /**
  * 分页带条件查询所有数据
  *
  * @param <T>
  * @param c 查询的表
  * @param condition 查询条件,用Cnd的静态方法构造
  * @param currentPage 当前页码
  * @param pageSize 每页显示的数据量
  * @return List
  */
 public <T> List<T> searchByPage(Class<T> c, Condition condition, int currentPage, int pageSize) {
   Pager pager = dao.createPager(currentPage, pageSize);
   return dao.query(c, condition, pager);
 }
Example #3
0
  /**
   * 分页带条件查询所有数据
   *
   * @param <T>
   * @param c 查询的表
   * @param condition 查询条件,用Cnd的静态方法构造
   * @param tem 需要封装的实体
   * @param currentPage 当前页码
   * @param pageSize 每页显示的数据量 @Param selectColumn 主键
   * @param returnColumn 需要封装的字段
   * @param relationId 外键
   * @return List
   */
  public <T> List<T> searchByPage(
      Class<T> c,
      Condition condition,
      Class cls,
      int currentPage,
      int pageSize,
      String selectColumn,
      String returnColumn,
      String relationId) {

    Pager pager = dao.createPager(currentPage, pageSize);
    List<T> list = dao.query(c, condition, pager);

    if (list == null || list.size() == 0) return list;
    Field field = null;
    StringBuilder sb = new StringBuilder();
    Map<Object, List<T>> map = new HashMap<Object, List<T>>();
    Object obj = null;
    for (T t : list) {
      try {
        field = t.getClass().getDeclaredField(selectColumn);
        field.setAccessible(true);
        obj = field.get(t);
        sb.append(obj).append(",");
      } catch (Exception e) {
        e.printStackTrace();
      }
      map.put(obj, new ArrayList<T>());
    }
    sb.append("0");
    try {

      List<T> relationList = this.searchByConditionIdss(cls, relationId, sb.toString(), null);
      for (T t : relationList) {

        try {
          field = t.getClass().getDeclaredField(relationId);
          field.setAccessible(true);
          obj = field.get(t);
          map.get(obj).add(t);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    } catch (Exception e1) {

      e1.printStackTrace();
    }

    Field temField = null;
    Object key = null;
    for (T t : list) {
      try {

        field = t.getClass().getDeclaredField(returnColumn);
        temField = t.getClass().getDeclaredField(selectColumn);
        field.setAccessible(true);
        temField.setAccessible(true);

        key = temField.get(t);
        field.set(t, map.get(key));

      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    return list;
  }
Example #4
0
 /**
  * 分页查询表中所有数据
  *
  * @param <T>
  * @param c 查询的表
  * @param currentPage 当前页数
  * @param pageSize 每页显示数量
  * @param orderby desc排序的条件
  * @return List
  */
 public <T> List<T> searchByPage(Class<T> c, int currentPage, int pageSize, String orderby) {
   Pager pager = dao.createPager(currentPage, pageSize);
   return dao.query(c, Cnd.orderBy().desc(orderby), pager);
 }