首页 > 其他 > 详细

HQL语句使用

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

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语句使用

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

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