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

📄 itembiz.java

📁 shoppingCar 购物车
💻 JAVA
字号:
package com.tarena.shoppingcar.biz;import java.util.HashSet;import java.util.List;import java.util.Set;import com.tarena.shoppingcar.dao.ItemDao;import com.tarena.shoppingcar.entity.Item;import com.tarena.shoppingcar.entity.Product;import com.tarena.shoppingcar.factory.ItemFactory;public class ItemBiz {	private ItemDao dao = ItemFactory.getDao();	public Set<Item> getItems(List<Product> products) {		Set<Item> items = new HashSet<Item>();		a: for (Product product : products) {			for (Item item : items) {				if (product.getId() == item.getProduct().getId()) {					item.setAmount(item.getAmount() + 1);					item.setCost(item.getCost() + product.getPrice());					continue a;				}			}			Item it = new Item();			it.setProduct(product);			it.setAmount(1);			it.setCost(product.getPrice());			items.add(it);		}		return items;	}	public void save(Set<Item> items,int id) {		dao.save(items,id);	}}

⌨️ 快捷键说明

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