码迷,mamicode.com
首页 > 其他好文 > 详细

HQL语句使用

时间:2014-08-13 22:16:57      阅读:323      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   使用   div   log   new   

1、查询结果是表的部分字段,而不是全部

  • ad是CouponAd 对象
  • coupon 是ad的属性,也是一个实体类

select ad.coupon from CouponAd ad where ad.deleted=false Order by createdDate desc 

2、like模糊搜索

这里变量key是String类型。

        String hql = "from Coupon coupon  where coupon.deleted=false and  coupon.name like :key";
        Map<String, Object> map = new HashMap<>();
        map.put("key", ‘%‘ + key + ‘%‘);
        List<T> list = list(hql, firstResult, maxResults, map);

3、查询总数

    public int getTotalCountByStore(int storeid) {
        Map<String, Object> map = new HashMap<>();
        map.put("storeid", storeid);
        return getTotalCount(
                "select count(*) from Coupon coupon where coupon.store.id=:storeid",
                map);
    }

 

Done!

HQL语句使用,布布扣,bubuko.com

HQL语句使用

标签:des   style   blog   color   使用   div   log   new   

原文地址:http://www.cnblogs.com/xingyyy/p/3911168.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!