hibernate查询返回一个list ,Date类型追加数据
Posted qingxin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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类型追加数据的主要内容,如果未能解决你的问题,请参考以下文章
Hibernate原生查询返回List Object List
转: 在hibernate中查询使用list,map定制返回类型
hibernate多表联合查询返回的list没有数据,但list.isEmpty()判断为啥不为真