首页 > 数据库技术 > 详细

Hibernate自定义数据库查询(排序、输出条数)

时间:2014-02-28 10:48:41      阅读:646      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
 1 Hibernate数据库操作类(eg:TexDAO.java)
 2 
 3     /*
 4      * queryString HQL语句,first开始条数, max输出条数 ,norder排序
 5      * 例: List lis = dao.findOther("from Tex",2,10," uid desc ");
 6      */
 7     public List findOther(String queryString, int first, int max, String norder) {
 8         StringBuffer sb = new StringBuffer();
 9 
10         // 这里是hibernate 对应的bean名并非实际表,这个实际对应的是视图
11         sb.append(queryString);
12 
13         // 从大到小排序
14         sb.append(" order by "+norder);
15         Query queryObject = getSession().createQuery(sb.toString());
16 
17         // 开始条数
18         queryObject.setFirstResult(first);
19 
20         // 输出条数
21         queryObject.setMaxResults(max);
22         return queryObject.list();
23     }
24 
25 
26 
27 Action业务逻辑类(eg:TexAction.java)
28 
29 public String list_tex2() {
30         lis = dao.findOther("from Tex",2,10," uid desc ");
31         
32         //测试
33         for (Tex t : lis) {
34             System.out.println("编号:" + t.getUid());
35             System.out.println("姓名:" + t.getUtname());
36         }
37         return "success";
38     }
bubuko.com,布布扣

Hibernate自定义数据库查询(排序、输出条数),布布扣,bubuko.com

Hibernate自定义数据库查询(排序、输出条数)

原文:http://www.cnblogs.com/huanglibin/p/3572088.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!