首页 > 代码库 > hibernate查询返回一个list ,Date类型追加数据

hibernate查询返回一个list ,Date类型追加数据

public Pagination getLookPage(BeanPatrolScheduling beanPatrolScheduling, int pageNo, int pageSize) {
        SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
          Pagination pagination = new Pagination();
          StringBuffer sql = new  StringBuffer();
          sql.append("      select   "); 
          
          sql.append("      ps.id,ju.username,ps.patrol_times,ps.patrol_month, ps.result,ps.parkid");
           
          sql.append("      from patrol_scheduling ps, ");
         
          sql.append("      company_emp ce, ");
          
          sql.append("      jc_user ju ");
               
          sql.append("      where ps.emp_id=ce.id ");
          
          sql.append("      and  ce.id=ju.user_id ");
          
          sql.append("      and ps.data_status=0");
          
          if(beanPatrolScheduling.getUserName()!= null && beanPatrolScheduling.getUserName()!= ""){
              sql.append("   and  ju.username like ‘%"+beanPatrolScheduling.getUserName()+"%‘" ); 
              
          }
          String sqls =  sql.toString();
          Query query =   sessionFactory.getCurrentSession().createSQLQuery(sqls.toString());
          List list = query.list();
          List<BeanPatrolScheduling> result=new ArrayList<BeanPatrolScheduling>();
            if(list!=null&&list.size()>0){
                
                 for (Object object : list) {
                        int i = 0;
                        BeanPatrolScheduling modell=new BeanPatrolScheduling();
                        Object[] temp = (Object[]) object;            
                        modell.setId(Integer.parseInt( temp[i++] +""));
                        modell.setUserName(String.valueOf( temp[i++]));
                        modell.setPatrol_times(Integer.parseInt( temp[i++] +""));
                        try {
                            modell.setPatrol_month(dateformat.parse( temp[i++] +""));
                        } catch (ParseException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        modell.setResult(Integer.parseInt( temp[i++] +""));
                        modell.setParkid(String.valueOf(temp[i++]));
                        result.add(modell);
                 }
             }
            
            pagination.setList(result);    
            pagination.setPageNo(pageNo);
            pagination.setPageSize(pageSize);
          
        return pagination;
    }

 

hibernate查询返回一个list ,Date类型追加数据