首页 > 学院 > 开发设计 > 正文

hql语句基础

2019-11-06 09:44:22
字体:
来源:转载
供稿:网友

面向对象的查询语言 Hibernate Query Language

@Test public void testhql() { // TODO Auto-generated method stub //模糊匹配 //%代表任意字符一个活多个 _代表单字符通配符 //select stu.sname,stu.sex from Student as stu where stu.sname like '%陈%' //select stu.sname,stu.sex from Student as stu where stu.sname like '陈_' //distinct出去查询结果中的关键字 String hqldistinct="select distinct stu.sex from Student as stu"; //默认以object[] 的形式返回 String hqlArray="select stu.sname,stu.sex from Student as stu"; //以list返回查询结果 String hqlList="select new List(stu.sname,stu.sex) from Student as stu"; //以Map的形式返回 返回查询结果 String hqlMaps="select new Map(stu.sname as name,stu.sex as sexs) from Student as stu"; //以自定的形式(需要在实体类中生命构造器) String hqlCustom="select new Student(stu.sname,stu.sex) from Student as stu"; Query query = session.createQuery(hqlList); List<List> list = query.list(); for (List list2 : list) { System.out.PRintln(list.get(0)); } }
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表