package com.lyq.action.product;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.lyq.action.BaseAction;
import com.lyq.model.PageModel;
import com.lyq.model.product.ProductCategory;
import com.lyq.model.product.ProductInfo;
import com.lyq.model.product.UploadFile;
import com.lyq.util.StringUitl;
import com.opensymphony.xwork2.ModelDriven;
/**
* 商品Action
* @author Li Yongqiang
*/
@Scope("prototype")
@Controller("productAction")
public class ProductAction extends BaseAction implements ModelDriven<ProductInfo>{
private static final long serialVersionUID = 1L;
/**
* 根据id查看商品信息(查看后更新人气点击次数)
* @return String
* @throws Exception
*/
public String select() throws Exception {
if(product.getId() != null && product.getId() > 0){
product = productDao.get(product.getId());
product.setClickcount(product.getClickcount() + 1);
productDao.update(product);
}
return SELECT;
}
/**
* 根据类别id查询所有商品信息
* @return String
* @throws Exception
*/
public String getByCategoryId() throws Exception{
if(product.getCategory().getId() != null){
String where = "where category.id = ?";
Object[] queryParams = {product.getCategory().getId()};
pageModel = productDao.find(pageNo, pageSize, where, queryParams);
}
return LIST;
}
/**
* 新品上市
* @return
* @throws Exception
*/
public String findNewProduct() throws Exception{
Map<String, String> orderby = new HashMap<String, String>();//定义Map集合
orderby.put("createTime", "desc");//为Map集合赋值
pageModel = productDao.find(1, 5, orderby );//执行查找方法
image.put("url", "01.gif");//设置副标题图片
return "list";//返回商品列表页面
}
/**
* 热销商品
* @return
* @throws Exception
*/
public String findSellProduct() throws Exception{
Map<String, String> orderby = new HashMap<String, String>();//定义Map集合
orderby.put("sellCount", "desc");//为Map集合赋值
pageModel = productDao.find(1, 5, orderby );//执行查找方法
image.put("url", "03.gif");
return "list";//返回商品列表页面
}
/**
* 推荐商品
* @return
* @throws Exception
*/
public String findCommendProduct() throws Exception{
Map<String, String> orderby = new HashMap<String, String>();//定义Map集合
orderby.put("createTime", "desc");//为Map集合赋值
String where = "where commend = ?";//设置条件语句
Object[] queryParams = {true};//设置参数值
pageModel = productDao.find(where, queryParams, orderby, 1, 5);//执行查询方法
image.put("url", "06.gif");
return "list";//返回商品列表页面
}
/**
* 人气商品
* @return
* @throws Exception
*/
public String findEnjoyProduct() throws Exception{
Map<String, String> orderby = new HashMap<String, String>();//定义Map集合
orderby.put("clickcount", "desc");//为Map集合赋值
pageModel = productDao.find(1, 5, orderby );//执行查找方法
image.put("url", "07.gif");
return "list";//返回商品列表页面
}
/**
* 根据名称模糊查询
* @return String
* @throws Exception
*/
public String findByName() throws Exception {
if(product.getName() != null){
String where = "where name like ?";//查询的条件语句
Object[] queryParams = {"%" + product.getName() + "%"};//为参数赋值
pageModel = productDao.find(pageNo, pageSize, where, queryParams );//执行查询方法
}
image.put("url", "04.gif");
return LIST;//返回列表首页
}
/**
* 按人气查询
* @return String
* @throws Exception
*/
public String findByClick() throws Exception{
Map<String, String> orderby = new HashMap<String, String>();//定义Map集合
orderby.put("clickcount", "desc");//为Map集合赋值
pageModel = productDao.find(1, 8, orderby );//执行查找方法
return "clickList";//返回product_click_list.jsp页面
}
/**
* 按推荐查询
* @return String
* @throws Exception
*/
public String findByCommend() throws Exception{
Map<String, String> orderby = new HashMap<String, String>();//定义Map集合
orderby.put("sellCount", "desc");//为Map集合赋值
String where = "where commend = ?";//设置条件语句
Object[] queryParams = {true};//设置参数值
pageModel = productDao.find(where, queryParams, orderby, pageNo, pageSize);//执行查询方法
return "findList";//返回product_find_list.jsp页面
}
/**
* 按销量查询
* @return String
* @throws Exception
*/
public String findBySellCount() throws Exception{
Map<String, String> orderby = new HashMap<String, String>();//定义Map集合
orderby.put("sellCount", "desc");//为Map集合赋值
pageModel = productDao.find(1, 6, orderby );//执行查询方法
return "findList";//返回热销商品列表
}
/**
* 添加商品
*/
@Override
public String add() throws Exception {
createCategoryTree();
return INPUT;
}
/**
* 保存商品
* @return
* @throws Exception
*/
public String save() throws Exception{
if(file != null ){//如果文件路径不为空
//获取服务器的绝对路径
String path = ServletActionContext.getServletContext().getRealPath("/upload");
File dir = new File(path);
if(!dir.exists()){//如果文件夹不存在
dir.mkdir();//创建文件夹
}
String fileName = StringUitl.getStringTime() + ".jpg";//自定义图片名称
FileInputStream fis = null;//输入流
FileOutputStream fos = null;//输出流
try {
fis = new FileInputStream(file);//根据上传文件创建InputStream实例
fos = new FileOutputStream(new File(dir,fileName)); //创建写入服务器地址的输出流对象
byte[] bs = new byte[1024 * 4]; //创建字节数组实例
int len = -1;
while((len = fis.read(bs)) != -1){//循环读取文件
fos.write(bs, 0, len);//向指定的文件夹中写数据
}
UploadFile uploadFile = new UploadFile();//实例化对象
uploadFile.setPath(fileName);//设置文件名称
product.setUploadFile(uploadFile);//设置上传路径
} catch (Exception e) {
e.printStackTrace();
}finally{
fos.flush();
fos.close();
fis.close();
}
}
//如果商品类别和商品类别ID不为空,则保存商品类别信息
if(product.getCategory() != null && product.getCategory().getId() != null){
product.setCategory(categoryDao.load(product.getCategory().getId()));
}
//如果上传文件和上传文件ID不为空,则保存文件的上传路径信息
if(product.getUploadFile() != null && product.getUploadFile().getId() != null){
product.setUploadFile(uploadFileDao.load(product.getUploadFile().getId()));
}
productDao.saveOrUpdate(product);//保存商品信息
return list();
}
/**
* 查询商品
* @return
* @throws Exception
*/
public String list() throws Exception{
pageModel = productDao.find(pageNo, pageSize);//调用公共的查询方法
return LIST;//返回后台商品列表页面
}
/**
* 编辑商品
* @return String
* @throws Exception
*/
public String edit() throws Exception{
this.product = productDao.get(product.getId());//执行封装的查询方法
createCategoryTree();//生成商品的类别树
return EDIT;//返回商品信息编辑页面
}
/**
* 删除商品
* @return String
* @throws Exception
*/
public String del() throws Exception{
productDao.delete(product.getId());//执行删除操作
return list();//返回商品列表查找方法
}
/**
* 生成类别树
*/
private void createCategoryTree(){
String where = "where level=1";//查询一级节点
PageModel<ProductCategory> pageModel = categoryDao.find(-1, -1,where ,null);//执行查询方法
List<ProductCategory> allCategorys = pageModel.getList();
map = new LinkedHashMap<Integer, String>();//创建新的集合
for(ProductCategory category : allCategorys){//遍历所有的一级节点
setNodeMap(map,category,false);//将节点添加到Map集合中
}
}
/**
* 将节点设置到Map中
* @pa
没有合适的资源?快使用搜索试试~ 我知道了~
javaweb淘天下网络商城
共476个文件
class:85个
jsp:85个
java:73个
需积分: 1 0 下载量 51 浏览量
2024-04-11
18:28:57
上传
评论
收藏 20.01MB ZIP 举报
温馨提示
淘天下网络商城是一个综合性的在线购物平台,旨在为用户提供丰富的商品选择和便捷的购物体验。该商城集成了各类商品,包括但不限于服装、电子产品、家居用品、图书、美妆等,满足消费者的多样化需求。 平台的核心特点包括: 商品多样性:淘天下网络商城提供广泛的商品类别,确保用户能够找到他们所需的各种产品。 用户友好的界面:设计简洁直观的网站布局和导航,使消费者能够轻松浏览和搜索商品。 安全支付系统:采用先进的支付技术,支持多种支付方式,如信用卡、支付宝、微信支付等,保障用户的交易安全。 高效的物流配送:与多家物流公司合作,提供快速可靠的配送服务,确保商品及时送达。 完善的售后服务:设立客服中心,处理用户的咨询和售后问题,提供退换货等便捷服务。 淘天下网络商城通过不断创新和优化,致力于提升用户的购物体验,同时也为商家提供了一个展示和销售产品的平台,促进了电子商务生态的健康发展。通过这个平台,消费者可以享受到一站式的购物便利,而商家则能够触及更广泛的客户群体,实现销售增长
资源推荐
资源详情
资源评论
收起资源包目录
javaweb淘天下网络商城 (476个子文件)
ProductAction.class 12KB
DaoSupport.class 7KB
OrderAction.class 7KB
StartExam.class 7KB
StudentDAO.class 6KB
QuestionsDAO.class 6KB
StartExamDAO.class 5KB
Student.class 5KB
QuestionsForm.class 5KB
BaseAction.class 5KB
Manager.class 4KB
TaoTiDAO.class 4KB
Questions.class 4KB
LessonDAO.class 4KB
Lesson.class 4KB
TaoTi.class 4KB
ProductInfo.class 4KB
EnumType.class 3KB
ProductCategoryAction.class 3KB
ManagerDAO.class 3KB
ConnDB.class 3KB
Order.class 3KB
CartAction.class 3KB
StuResultDAO.class 3KB
DaoSupport$2.class 3KB
CustomerAction.class 3KB
IndexAction.class 3KB
StudentForm.class 3KB
StuResult.class 2KB
ProductCategory.class 2KB
ProductDaoImpl.class 2KB
UserAction.class 2KB
OrderItem.class 2KB
PageModel.class 2KB
CustomerDaoImpl.class 2KB
HibernateUtils.class 2KB
UserDaoImpl.class 2KB
OrderState.class 2KB
Customer.class 2KB
StuResultForm.class 2KB
ChStr.class 2KB
Sex.class 2KB
TaoTiForm.class 2KB
StringUitl.class 2KB
OrderDaoImpl.class 1KB
DaoSupportTest.class 1KB
temp.class 1KB
PaymentWay.class 1KB
CustomerLoginInteceptor.class 1KB
UserLoginInterceptor.class 1KB
LessonForm.class 1KB
DaoSupport$1.class 1KB
OrderStateConversion.class 1KB
PaymentWayConversion.class 1KB
AppException.class 1KB
SexConversion.class 1KB
BaseDao.class 1KB
ManagerForm.class 1KB
User.class 1KB
GenericsUtils.class 993B
SelfRequestProcessor.class 904B
UploadFile.class 888B
QueryResultIfForm.class 771B
ProductCategoryDaoImpl.class 631B
MoreSelect.class 599B
UploadFileDaoImpl.class 596B
PaymentWay$1.class 547B
PaymentWay$3.class 541B
OrderState$2.class 541B
PaymentWay$4.class 541B
OrderState$3.class 538B
OrderState$1.class 538B
PaymentWay$2.class 538B
Sex$3.class 500B
Sex$1.class 497B
Sex$2.class 497B
PaymentWayType.class 471B
OrderStateType.class 471B
SexType.class 436B
ProductDao.class 421B
CustomerDao.class 369B
UserDao.class 353B
OrderDao.class 291B
ProductCategoryDao.class 267B
UploadFileDao.class 252B
.classpath 4KB
.classpath 1KB
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.container 49B
style_index.css 6KB
style_ht.css 3KB
style.css 2KB
Thumbs.db 90KB
.DS_Store 6KB
bg_03.gif 42KB
index_25.gif 37KB
dl_03.gif 18KB
ht_02_01.gif 18KB
03.gif 9KB
04.gif 9KB
共 476 条
- 1
- 2
- 3
- 4
- 5
资源评论
趙兴晨
- 粉丝: 1059
- 资源: 192
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功