Hibernate数据库操作类(eg:TexDAO.java) /*
* queryString HQL语句,first开始条数, max输出条数 ,norder排序
* 例: List lis = dao.findOther("from Tex",2,10," uid desc ");
*/
public List findOther(String queryString, int first, int max, String norder) {
StringBuffer sb = new StringBuffer(); // 这里是hibernate 对应的bean名并非实际表,这个实际对应的是视图
sb.append(queryString); // 从大到小排序
sb.append(" order by "+norder);
Query queryObject = getSession().createQuery(sb.toString()); // 开始条数
queryObject.setFirstResult(first); // 输出条数
queryObject.setMaxResults(max);
return queryObject.list();
} Action业务逻辑类(eg:TexAction.java) public String list_tex2() {
lis = dao.findOther("from Tex",2,10," uid desc "); //测试
for (Tex t : lis) {
System.out.println("编号:" + t.getUid());
System.out.println("姓名:" + t.getUtname());
}
return "success";
}