/** * 根据提供的数量获取随机的问题列表 * @param totel * @return */ public List getRadomQuestionList(final Integer tot){ List res = null; final Integer totel = tot == null ? new Integer(1) : tot; res = baseDao.getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session s) { Criteria c = s.createCriteria(Question.class); int resSize =c.list().size(); Random r=new Random(); int n = resSize - totel.intValue(); return c.setFirstResult(r.nextInt(n)+1).setMaxResults(totel.intValue()).list(); } }); if(null != res && res.size() > 0){ for (int i = 0; i < res.size(); i++) { Question ques = (Question)res.get(i); ques = this.getRadomQuestionAndAnswerByQuestion(ques); } } return res; }