Exemplo n.º 1
0
 /** 分页加载所有文件; */
 @SuppressWarnings("unchecked")
 public ArrayList<FileBean> loadPageFile(PageBean pageBean, HttpSession httpSession) {
   User u = (User) httpSession.getAttribute("u");
   Query q =
       sessionFactory
           .getCurrentSession()
           .createQuery("from File file where file.user.id=" + u.getId());
   q.setFirstResult(pageBean.getStart());
   q.setMaxResults(pageBean.getRows());
   ArrayList<com.ligongcloud.model.File> files = (ArrayList<com.ligongcloud.model.File>) q.list();
   ArrayList<FileBean> fileBeans = FileUtil.formatFile(files);
   return fileBeans;
 }
Exemplo n.º 2
0
  /** 查询文件; */
  @SuppressWarnings("unchecked")
  public ArrayList<FileBean> searchFile(
      String name,
      String s_screateDate,
      String s_ecreateDate,
      PageBean pageBean,
      HttpSession httpSession)
      throws Exception {
    User u = (User) httpSession.getAttribute("u");

    StringBuffer sqlBuffer =
        new StringBuffer("from File file where file.user.id=" + u.getId() + " ");

    if (StringUtil.isNotEmpty(name)) {
      sqlBuffer.append("and file.name = '" + name + "' ");
    }

    if (StringUtil.isEmpty(s_screateDate)) {
      s_screateDate = "2010-01-01";
    }

    if (StringUtil.isEmpty(s_ecreateDate)) {
      // 如果s_ejoindate为空,设s_ejoindate为当前系统时间
      SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
      s_ecreateDate = df.format(new Date());
    }

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 小写的mm表示的是分钟
    Date begin = sdf.parse(s_screateDate);
    Date end = sdf.parse(s_ecreateDate);

    sqlBuffer.append("and file.createDate > :beginTime and file.createDate <= :endTime");
    Query q =
        sessionFactory
            .getCurrentSession()
            .createQuery(sqlBuffer.toString())
            .setTimestamp("beginTime", begin)
            .setTimestamp("endTime", end);
    q.setFirstResult(pageBean.getStart());
    q.setMaxResults(pageBean.getRows());

    ArrayList<File> files = (ArrayList<File>) q.list();
    ArrayList<FileBean> fileBeans = FileUtil.formatFile(files);
    return fileBeans;
  }