1 public List<Student> querySomeStudent(String serachText){ 2 Transaction tx = null; 3 String hql=""; 4 try{ 5 Session session = MyHibernateSessionFactory.getSessionFactory().getCurrentSession(); 6 tx = session.beginTransaction(); 7 hql="from Student where"; 8 StringBuffer hqlsb = new StringBuffer(); 9 hqlsb.append("studentName like ? or "); 10 hqlsb.append("studentNum like ? or "); 11 hqlsb.append("cellNum like ? or "); 12 hqlsb.append("className like ?"); 13 hql+=hqlsb; 14 Query query = session.createQuery(hql).setString(1, "'%serachText%'").setString(2, "'%serachText%'") 15 .setString(3, "'%serachText%'").setString(4, "'%serachText%'");//生成一个Query对象 16 List list= query.list(); 17 tx.commit(); 18 return list; 19 } 20 catch(Exception ex) 21 { 22 ex.printStackTrace(); 23 tx.commit(); 24 return null; 25 } 26 finally 27 { 28 if(tx!=null) 29 { 30 tx=null; 31 } 32 } 33 }
桃花长相依
慕慕森
波斯汪
拉莫斯之舞
繁花不似锦
HUH函数
aluckdog
慕运维8079593
小唯快跑啊
三国纷争
相关分类