⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fooddao.java

📁 点餐系统 非常好的 jsp mysql 我也是别人那里下载来的
💻 JAVA
字号:
package com.accp.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;


public class FoodDAO {
	public Goods GetFoodById(int id)
	{
		Goods goods=new Goods();
		try {
			Session session=HibernateSessionFactory.getSession();			
			goods=(Goods)session.load(UserInfo.class, id);	
			System.out.println("getfoodbyid="+goods.getGname());
			
		} catch (Exception e) {
			System.out.println("根据商品的id查询出现异常!"+e.toString());			
			e.printStackTrace();
		}
		return goods;	
		
	}
	public List GetFoodsByTypeId(String typeid)
	{
		
		Query query=null;
		try {
			Session session=HibernateSessionFactory.getSession();
			String hql="from Goods where gtype="+typeid;
			System.out.println("hql="+hql);
			query=session.createQuery(hql);			
			
		} catch (Exception e) {
			System.out.println("根据商品的类型查询出现异常"+e.toString());
			// TODO: handle exception
		}
		return query.list();		
	}
	
	public Set queryfood(String did)
	{
		try {
			Session sess=HibernateSessionFactory.getSession();
			TypeGoods dep=(TypeGoods)sess.load(TypeGoods.class,new Integer(did));
			return dep.getGoodses();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return null;
		
	}
	public int GetTotalnum(String typeid)
	{
		int count=0;
		try {
			Session sess=HibernateSessionFactory.getSession();
			//HQL语句的使用
			String hql="select count(g) from Goods as g where gtype="+typeid;
		    Query query=sess.createQuery(hql);
		    count=(Integer)query.uniqueResult();
		    
		    //Criteria完全面向对象查询的应用
	    	//Criteria ca=sess.createCriteria(Goods.class);
	    	//ca.add(Restrictions.eq("gtype", typeid));
	       // ca.add(Restrictions.or(Restrictions.like("userName", "1", MatchMode.ANYWHERE), Restrictions.like("userName", "k", MatchMode.ANYWHERE)));
					
			
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}
		return count;
	}
	public List GetEveryPageInfo(int index,int pagesize,String typeid)
	{
		List list=null;
		try {
			Session session=HibernateSessionFactory.getSession();
			String hql="from Goods where gtype="+typeid;
			Query query=session.createQuery(hql);
			query.setFirstResult(index);
			query.setMaxResults(pagesize);
			//query.setInteger(0, new Integer(typeid));
			list=query.list();			
			
		} catch (Exception e) {
			System.out.println("查询每页显示的数据出现异常!"+e.toString());
			// TODO: handle exception
		}
		return list;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -