㈠ java編程 購物車刪除的物品恢復這個功能怎麼實現
這個跟JAVA沒什麼關系吧,想好設計思路就行了,你可以做個備份表啊,刪除的物品先放到這里,過了1個鍾頭清除就好了
㈡ java購物車清空返回,不知道如何把它們組合在一起,點擊返回並清空就可以實現他們的功能,就教!
先返回中間一個過渡頁面,在這個頁面中清空購物車,然後再跳轉到產品選擇頁面
㈢ JSP+JAVABEAN+SERVLET模式的購物車 如何清空購物車。。
把購物信息存入session中。清空購物車只管清空session中key對就的value.
㈣ 求一個JAVA里用map集合寫一個購物車的代碼,購物車實現商品的添加,刪除,查詢和結算,寫了半天沒
建一個靜態的Map集合 做購物車的集合
key值 放商品的ID value 放 商品對象.
對map 增刪改查就好了.. 結算完了 清空map
㈤ java程序中購物車中的訂單刪除後能刪除數據嗎
存在session里 就直接刪除session 數據 但是現在一般都是登錄後 存在資料庫里的
㈥ Java使用字元串生成器來保存購物車中的商品信息,並能實現商品信息的添加、刪除以及修改等功能
publicclassCart{
publicStringBuilderdata;
publicfloattotal;
publicCart(){
data=newStringBuilder();
}
publicvoidbuy(Goodsg){
g.gtotal=g.gnum*g.gprice;
total=total+g.gtotal;
data.append("[");
data.append(g.gname+"|");
data.append(g.gprice+"|");
data.append(g.gnum+"|");//還是豎線看著方便
data.append(g.gtotal);
data.append("]");
}
publicvoiddelete(Goodsg){
ints=data.indexOf(g.gname);
inte=data.indexOf("]",s);
data.delete(s-1,e+1);
total=total-g.gtotal;//刪除商品,需要修改總額
}
publicvoipdate(Goodsg){
data.replace(3,10,"["+g.gname+"|"+g.gprice+"|"+g.gnum+"|"+g.gtotal);
}
publicvoidshow(){
System.out.print("總計金額:"+total+"");
System.out.println(data);
}
}
//Excute類里有點小錯誤,
//總覺得update方法不對頭,你想怎麼做?
㈦ 此段JAVA servelet代碼 清空購物車哪裡有問題
cart.clear() ;
㈧ java購物車用servlet做,sql資料庫,能實現基本增加、刪除、修改商品,結賬,然後下訂單,求源代碼
加入購物車的代碼:
//把商品保存到session中
HttpSession session=request.getSession();
List<Goods> list=(List) session.getAttribute("list");
int gid=Integer.parseInt(request.getParameter("gid"));
int num=Integer.parseInt(request.getParameter("num"));
Goods goods=null;
if(list==null || list.size()<0){
list=new ArrayList();
}else{
for (Goods g : list) {
if(g.getGid()==gid){
goods=g;
g.setSum(g.getSum()+num);
break;
}
}
}
if(goods==null){
goods=goodsDao.queryGoodsByG_id(gid);
goods.setSum(num);
list.add(goods);
}
session.setAttribute("list", list);
request.getRequestDispatcher("/index.jsp").forward(request, response);
增加、刪除、修改商品差不多,只是sql語句不同
㈨ 購物車的Java代碼
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;public class ShoppingCartManager {
HashMap<String, String> hm=new HashMap<String, String>();
float totlePrice=0;
//添加book到購物車
public void addBook(String bookId,String bookQuantity){
if(hm.containsKey(bookId)){
int value=Integer.parseInt(hm.get(bookId));
value+=Integer.parseInt(bookQuantity);
hm.put(bookId, value+"");
}else{
hm.put(bookId, bookQuantity);
}
}
//修改數量
public void updateQuantity(String bookId,String bookQuantity){
hm.put(bookId, bookQuantity);
}
//獲取購物車的所有信息 並計算總價
public ArrayList<BookBean> getShoppingCart(){
ArrayList<BookBean> al=new ArrayList<BookBean>();
Iterator<String> i=hm.keySet().iterator();
String ids="";
BookTableManager btm=new BookTableManager();
while(i.hasNext()){
ids=ids+","+i.next();
}
al= btm.selectByBookIds(ids);
totlePrice=0; //清空總價,防止無限累計
for(int j=0;j<al.size();j++){
BookBean bb=al.get(j);
totlePrice+=bb.getPrice()*Integer.parseInt(getQuantityById(bb.getBookId()+""));
}
return al;
}
//獲取總價
public float getTotlePrice(){
return totlePrice;
}
//根據ID獲取數量
public String getQuantityById(String id){
String quantity=hm.get(id);
return quantity;
}
//清空購物車
public void clear(){
hm.clear();
}
//刪除購物車中的一本書
public void deleteById(String id){
hm.remove(id);
}
}