zoukankan      html  css  js  c++  java
  • 查询 java 或 oracle 或 jsp的图书

    创建一个Criteria实例 net.sf.hibernate.Criteria这个接口代表对一个特定的持久化类的查询。Session是用来制造Criteria实例的工厂。

    package com.haha.test3;

    import java.util.List;

    import org.hibernate.Criteria;
    import org.hibernate.criterion.Criterion;
    import org.hibernate.criterion.MatchMode;
    import org.hibernate.criterion.Restrictions;

    import com.haha.dao.HibernateSessionFactory;
    import com.haha.info.Books;

    public class Test或者查询 {


    public static void main(String[] args) {
    //查询 java 或 oracle 或 jsp的图书
    Criteria crit=HibernateSessionFactory.getSession()
    .createCriteria(Books.class);

    Criterion where1=Restrictions.ilike("title", "java",MatchMode.ANYWHERE);
    Criterion where2=Restrictions.ilike("title", "oracle",MatchMode.ANYWHERE);
    Criterion where3=Restrictions.ilike("title", "jsp",MatchMode.ANYWHERE);

    Criterion where4=Restrictions.or(where1, where2);

    crit.add(Restrictions.or(where3, where4));

    List<Books> list=crit.list();
    for(Books bk:list){
    System.out.println(bk.getTitle()+","+bk.getUnitprice());
    }
    System.out.println("共有"+list.size()+"条");

    }

    }

    第二种方法

     

  • 相关阅读:
    大道至简阅读笔记01
    3.2-3.8 第三周总结
    全国疫情统计可视化地图 01
    数据爬取
    全国疫情统计可视化地图
    第3周总结
    第2周总结
    开课博客
    数组
    从小工到专家 读后感2
  • 原文地址:https://www.cnblogs.com/tian114527375/p/4962488.html
Copyright © 2011-2022 走看看