hibernate通过sql语句查询出的结果集封装到bean里面去

相关的语句有

 

  String sql="select t_personalbaseinfoentity.realName," +
      "t_personalbaseinfoentity.mobilePhone," +
      "t_personalbaseinfoentity.phone," +
      "t_personalbaseinfoentity.mail," +
      "t_personalbaseinfoentity.qq "+
      "from t_personalbaseinfoentity";

  getSession().createSQLQuery(sql).setResultTransformer(Transformers.aliasToBean(AddressBookInfo.class)).list();

其中AddressBookInfo这个bean中必须要有与查询出来的字段名相同的属性,即这里的bean里需要realName,mobilePhone,phone,mail,qq几个属性以及它们的设置器,即setter,查询结果即可返回List

你可能感兴趣的:(JAVA)