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

📄 orderdaoimpl.java

📁 该系统的主要功能是
💻 JAVA
字号:
package com.laoniu.dao.impl;

import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import org.hibernate.Query;
import org.hibernate.Session;


import com.laoniu.bean.Book;
import com.laoniu.bean.Orderform;
import com.laoniu.dao.IOrderDao;
import com.laoniu.common.HibernateSessionFactory;

public class OrderDaoImpl implements IOrderDao {
	//删除订单
	public void deleteOrder(Orderform order) throws Exception {
		// TODO Auto-generated method stub
		Session session=HibernateSessionFactory.getSession();
		session.delete(order);
		System.out.println("**************此订单已经删除******************");
	}
	//查看所有的图书
	public Map<Long, Book> findAllBook() throws Exception {
		Map<Long, Book> map=new TreeMap<Long,Book>();
		
		Session session=HibernateSessionFactory.getSession();
		Query query=session.createQuery("from Book");
		List<Book> list=query.list();
		for(Book book :list){
			map.put(book.getId(), book);
		}
		
		return map;
	}
	//查看当前用户的所有的订单
	public Map<Long, Orderform> findAllOrder(Long customerid) throws Exception {
		Map<Long,Orderform> map=new TreeMap<Long,Orderform>();
		Session session=HibernateSessionFactory.getSession();
		Query query=session.createQuery("from Orderform where customerid='"+customerid+"'");
		
		List<Orderform> list=query.list();
		for(Orderform order : list){
			map.put(order.getId(), order);
		}
		return map;
	}
	//查看某一订单
	public Orderform findOrderById(Long orderid) throws Exception {
		Session session=HibernateSessionFactory.getSession();
		Orderform order=(Orderform)session.get(Orderform.class, orderid);
		return order;
	}
	//保存订单
	public void saveOrder(Orderform order) throws Exception {
		Session session=HibernateSessionFactory.getSession();
		session.save(order);
	}
	//查询所用订单
	public Map<Long, Orderform> listAllOrder() throws Exception 
	{
		Map<Long,Orderform> orders=new TreeMap<Long,Orderform>();
		Session session=HibernateSessionFactory.getSession();
		String hql="from Orderform";
		Query query=session.createQuery(hql);
		List<Orderform> list=query.list();
		for(Object o:list)
		{
			Orderform orderform=(Orderform)o;
			orders.put(orderform.getId(),orderform);
		}
		return orders;
	}
	//删除订单
	public void deleteBook(Long bookid) throws Exception 
	{
		Book book=null;
		Session session=HibernateSessionFactory.getSession();
		String hql="from Book where id=?";
		Query query=session.createQuery(hql);
		query.setLong(0, bookid);
		book=(Book)query.uniqueResult();
		session.delete(book);
		System.out.println("删除成功");
	}
	public Book findBookbyid(Long id) throws Exception 
	{
		Session session=HibernateSessionFactory.getSession();
		String hql="from Book where id=?";
		Query query=session.createQuery(hql);
		query.setLong(0, id);
		return (Book)query.uniqueResult();
	}
	public void addBook(Book book) throws Exception {
		Session session=HibernateSessionFactory.getSession();
		session.save(book);
	}
	
	/*public static void main(String args[]){
		Map<Long, Book> map=null;
		OrderDaoImpl dao=new OrderDaoImpl();	   
		Configuration config=new Configuration();
		config.configure();
		SessionFactory factory=config.buildSessionFactory();
		Session session=factory.openSession();
		Transaction tran=session.beginTransaction();
		   
		try {
			map=dao.findAllBook();
			for( Entry entry : map.entrySet()){
				System.out.println(entry.getKey());
				System.out.println(entry.getValue());
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}   
		
		   
		tran.commit();
		   
		session.close();
	}*/
	
}

⌨️ 快捷键说明

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