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

📄 buycarbean.java

📁 J2EE上课详细课件,精通J2EE编程教程.
💻 JAVA
字号:
package j2ee.ejbBuyCar;
import java.io.Serializable;
import java.util.Hashtable;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
//业务实现EJB类
public abstract class buyCarBean implements SessionBean,Serializable {
	Hashtable myGoods=new Hashtable();
	//EJB被激活时调用
	public void ejbActivate() throws EJBException {
		System.out.println("EJB被激活了!");
	}
	//EJB被钝化时调用
	public void ejbPassivate() throws EJBException {
		System.out.println("EJB被钝化了!");
	}
	//EJB消亡时调用
	public void ejbRemove() throws EJBException {
		System.out.println("EJB被删除了!");
	}
	//初始化设置会话上下文时调用
	public void setSessionContext(SessionContext arg0) throws EJBException {
		System.out.println("设置会话上下文!");
	}
	//创建EJB时调用
	public void ejbCreate() throws EJBException{
    	System.out.println("创建EJB!");
    }
	//把商品加入购物车
	public void addGoods(String Goods_Name,int Goods_Count) { 
	    if(myGoods.containsKey(Goods_Name))
	    {//购物车中存在此商品则累加个数
	      int Temp_Count=((Integer)myGoods.get(Goods_Name)).intValue();
	      Temp_Count=Temp_Count+Goods_Count;
	      myGoods.put(Goods_Name,new Integer(Temp_Count));
	    }else
	    {//购物车中不存在此商品
	      myGoods.put(Goods_Name,new Integer(Goods_Count));
	     }
	   }
	  //把商品从购物车中拿出
	  public boolean minusGoods(String Goods_Name,int Goods_Count){
	    if(myGoods.containsKey(Goods_Name))
	    {//购物车中存在此商品则减少个数
	      int Temp_Count=((Integer)myGoods.get(Goods_Name)).intValue();
	      Temp_Count=Temp_Count-Goods_Count;
	      if(Temp_Count<=0)  
	        deleteGoods(Goods_Name);
	      else
	        myGoods.put(Goods_Name,new Integer(Temp_Count));
	      return true;
	    }
	    else{//购物车中不存在此商品
	      return false;
	     }
	   }
	  //从购物车中删除一件商品
	  public boolean deleteGoods(String Goods_Name){
	     if(myGoods.remove(Goods_Name)==null)
	       return false;
	     else
	       return true;
	   }  
	  //得到购物车中所有商品
	  public Hashtable listMyGoods(){
	     return myGoods;
	   } 
}

⌨️ 快捷键说明

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