예제 #1
0
  /**
   * 根据多个id 查询数据
   *
   * @param <T>
   * @param ids 整形的id数组
   * @param c 要查询的表信息
   * @return List
   */
  public <T> List<T> searchByIds(Class<T> c, int[] ids, String orderby) {

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

    String id = entity.getIdField().getColumnName();

    return dao.query(c, Cnd.where(id, "in", ids).desc(orderby), null);
  }
예제 #2
0
  /**
   * 根据多个id 查询数据
   *
   * @param <T>
   * @param ids 要查询的id,多个用","(逗号)分隔
   * @param c 要查询的表信息
   * @return List
   */
  public <T> List<T> searchByIds(Class<T> c, String ids, String orderby) {

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

    String id = entity.getIdField().getColumnName();

    String sql = " " + id + " in (" + ids + ") order by " + orderby + " desc";

    return dao.query(c, Cnd.wrap(sql), null);
  }
예제 #3
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);
  }
예제 #4
0
  /**
   * 根据多个id 查询数据并且分页
   *
   * @param <T>
   * @param ids 要查询的id,多个用","(逗号)分隔
   * @param c 要查询的表信息
   * @return List
   */
  public <T> int searchByIdsCount(
      Class<T> c, String ids, String orderby, int currentPage, int pageSize) {

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

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

    String id = entity.getIdField().getColumnName();

    String sql = " " + id + " in (" + ids + ") order by " + orderby + " desc ";
    return dao.query(c, Cnd.wrap(sql), null).size();
  }
예제 #5
0
  public <T> List<T> searchByConditionIdss(
      Class<T> c, String column, String ids, String orderby, int curPage, int pagesize) {
    String sql =
        " "
            + column
            + " in ("
            + ids
            + ") order by "
            + orderby
            + " desc limit "
            + (curPage - 1) * pagesize
            + ", "
            + pagesize
            + "";

    return dao.query(c, Cnd.wrap(sql), null);
  }
예제 #6
0
  /**
   * 根据多个id 查询数据并且分页
   *
   * @param <T>
   * @param ids 要查询的id,多个用","(逗号)分隔
   * @param c 要查询的表信息
   * @return List
   */
  public <T> List<T> searchByIdsFenye(
      Class<T> c, String ids, String orderby, int currentPage, int pageSize) {

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

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

    String id = entity.getIdField().getColumnName();

    String sql =
        " "
            + id
            + " in ("
            + ids
            + ") order by "
            + orderby
            + " desc limit "
            + (currentPage - 1) * pageSize
            + ", "
            + pageSize
            + "";

    return dao.query(c, Cnd.wrap(sql), null);
  }
예제 #7
0
  /**
   * 查询数据库中的全部数据
   *
   * @param <T>
   * @param c 查询的表
   * @param orderby desc 排序的条件
   * @return List
   */
  public <T> List<T> search(Class<T> c, String orderby) {

    return dao.query(c, Cnd.orderBy().desc(orderby), null);
  }
예제 #8
0
  public List<Record> query(String joinT, Condition condition) {

    return dao.query(joinT, condition, null);
  }
예제 #9
0
  public <T> int searchCountByConditionIdss(
      Class<T> c, String column, String ids, String orderby, int curPage, int pagesize) {
    String sql = " " + column + " in (" + ids + ") order by " + orderby + " desc ";

    return dao.query(c, Cnd.wrap(sql), null).size();
  }
예제 #10
0
  /**
   * 根据多个id 查询数据
   *
   * @param <T>
   * @param ids 要查询的id,多个用","(逗号)分隔
   * @param c 要查询的表信息
   * @return List
   */
  public <T> List<T> searchByConditionIdss(Class<T> c, String column, String ids, String orderby) {

    String sql = " " + column + " in (" + ids + ") order by " + orderby + " desc";

    return dao.query(c, Cnd.wrap(sql), null);
  }
예제 #11
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;
  }
예제 #12
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);
 }
예제 #13
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);
 }
예제 #14
0
 /**
  * 根据条件查询数据库中满足条件的数据
  *
  * @param <T>
  * @param c
  * @param condition
  * @return
  */
 public <T> List<T> search(Class<T> c, Condition condition) {
   List<T> list = dao.query(c, condition, null);
   return list;
 }