• Hibernate_HQL


    public class According_condition {
    public static void main(String[]args){
    Session session=HibernateUtil.getSession();
    List<Book2> zzy=new ArrayList<>();
    String HQL="from Book2 bo where bo.bookCount=2000";
    Query W=session.createQuery(HQL);
    zzy=W.list();
    Iterator iterator=zzy.iterator();
    while(iterator.hasNext())
    System.out.println(iterator.next());
    }
    }



    /**
    * Created by Administrator on 2015/12/16.
    *这是用来测试分页查询的类。
    */
    public class Page_query {
    public static void main(String[]args){
    Session session= HibernateUtil.getSession();
    List<Book2> zzy=new ArrayList<>();
    String HQL="from Book2 bo";
    Query W=session.createQuery(HQL);
    int pageNo=3;
    int pageSize=4;
    zzy=W.setFirstResult(0).setMaxResults(pageSize).list();
    /**对应的两个方法setFirstResult设定从哪一个对象开始检索,默认情况下从0开始
    * setMaxResults设定一次对多检索出来的对象的数目**/
    Iterator iterator=zzy.iterator();
    while(iterator.hasNext())
    System.out.println(iterator.next());
    }
    }



    /**
    * Created by Administrator on 2015/12/15.
    * 这是一个用来测试绑定参数的测试类,绑定参数的方式用?的方式
    */
    public class parameter_binding_HQL {
    public static void main(String[]args) {
    Session session = HibernateUtil.getSession();
    List<Book2> zzy=new ArrayList<>();
    String HQL="from Book2 bo where bo.bookCount=?";
    Query query=session.createQuery(HQL);
    query.setParameter(0,2000);
    zzy=query.list();
    Iterator iterator=zzy.iterator();
    while(iterator.hasNext())
    System.out.println(iterator.next());
    }
    }



    /**
    * Created by Administrator on 2015/12/15
    * 这是一个用来测试绑定参数的类,这里用的是:参数的放来来绑定参数.
    */
    public class parameter_binding_HQL_new {
    public static void main(String[]args) {
    Session session = HibernateUtil.getSession();
    List<Book2> zzy=new ArrayList<>();
    String HQL="from Book2 bo where bo.bookCount=:count";
    Query query=session.createQuery(HQL);
    query.setParameter("count",1222);
    zzy=query.list();
    Iterator iterator=zzy.iterator();
    while(iterator.hasNext())
    System.out.println(iterator.next());
    }
    }



    /**
    * Created by Administrator on 2015/12/15.
    * 这个类用来使用HQL语句来查询所有的对象。
    */
    public class select_all {
    public static void main(String[]args){
    Session session= HibernateUtil.getSession();
    List<Book2> zzy=new ArrayList<Book2>();
    String HQL="from Book2 bo";
    Query W=session.createQuery(HQL);
    zzy=W.list();
    Iterator iterator=zzy.iterator();
    while(iterator.hasNext())
    System.out.println(iterator.next());
    }
    }



    /**
    * Created by Administrator on 2015/12/15.
    * 这是一个可以根据降序和升序排序的HQL查询语句
    */
    public class sort_query {
    public static void main(String[]args){
    Session session= HibernateUtil.getSession();
    List<Book2> zzy=new ArrayList<Book2>();
    String HQL="from Book2 bo order by bo.id desc";
    //desc是降序,asc是升序
    Query W=session.createQuery(HQL);
    zzy=W.list();
    Iterator iterator=zzy.iterator();
    while(iterator.hasNext())
    System.out.println(iterator.next());
    }
    }
  • 相关阅读:
    微软职位内部推荐-Senior Software Engineer
    微软职位内部推荐-Senior Software Engineer
    微软职位内部推荐-Software Development Engineer
    微软职位内部推荐-Senior Dev Lead
    微软职位内部推荐-Software Engineer II_HPC
    微软职位内部推荐-Senior Software Engineer
    微软职位内部推荐-Senior SW Engineer for Application Ecosystem
    微软职位内部推荐-Senior Software Engineer-Eco
    微软职位内部推荐-Software Development Engineer II
    微软职位内部推荐-Senior Software Lead-Index Gen
  • 原文地址:https://www.cnblogs.com/41ZZY/p/5330649.html
Copyright © 2020-2023  润新知