package action;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.persistence.criteria.Order;
import org.apache.struts2.ServletActionContext;
import org.hibernate.mapping.Collection;
import utils.MyFileUtil;
import com.opensymphony.xwork2.ActionSupport;
import dao.EvaluationDao;
import dao.OrderShoesDao;
import dao.ShoesDao;
import daoImpl.ShoesDaoImpl;
import entity.Brand;
import entity.Client;
import entity.Evaluation;
import entity.OrderShoes;
import entity.Shoes;
public class ShoesAction extends SuperAction {
private ShoesDao shoesDao;
private Brand brand;
private List<OrderShoes> shoppingCarShoes;
private Shoes shoes;
private Evaluation evaluation;
private EvaluationDao evaluationDao;
private MyFileUtil brandPhoto;
private MyFileUtil evaluationPhoto;
private MyFileUtil smallPhoto;
private MyFileUtil bigPhoto;
private OrderShoesDao orderShoesDao;
private String searchStr;
public MyFileUtil getBrandPhoto() {
return brandPhoto;
}
public void setBrandPhoto(MyFileUtil brandPhoto) {
this.brandPhoto = brandPhoto;
}
public String getSearchStr() {
return searchStr;
}
public void setSearchStr(String searchStr) {
this.searchStr = searchStr;
}
public OrderShoesDao getOrderShoesDao() {
return orderShoesDao;
}
public void setOrderShoesDao(OrderShoesDao orderShoesDao) {
this.orderShoesDao = orderShoesDao;
}
public MyFileUtil getEvaluationPhoto() {
return evaluationPhoto;
}
public void setEvaluationPhoto(MyFileUtil evaluationPhoto) {
this.evaluationPhoto = evaluationPhoto;
}
public MyFileUtil getSmallPhoto() {
return smallPhoto;
}
public void setSmallPhoto(MyFileUtil smallPhoto) {
this.smallPhoto = smallPhoto;
}
public MyFileUtil getBigPhoto() {
return bigPhoto;
}
public void setBigPhoto(MyFileUtil bigPhoto) {
this.bigPhoto = bigPhoto;
}
public Evaluation getEvaluation() {
return evaluation;
}
public void setEvaluation(Evaluation evaluation) {
this.evaluation = evaluation;
}
public EvaluationDao getEvaluationDao() {
return evaluationDao;
}
public void setEvaluationDao(EvaluationDao evaluationDao) {
this.evaluationDao = evaluationDao;
}
public Shoes getShoes() {
return shoes;
}
public void setShoes(Shoes shoes) {
this.shoes = shoes;
}
public ShoesDao getShoesDao() {
return shoesDao;
}
public void setShoesDao(ShoesDao shoesDao) {
this.shoesDao = shoesDao;
}
public Brand getBrand() {
return brand;
}
public void setBrand(Brand brand) {
this.brand = brand;
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println("execute");
// queryShoesByBrand();
return SUCCESS;
}
public String queryAllShoes() {
queryAllBrand();
List<Shoes> shoesList = shoesDao.getAllShoes();
if (shoesList != null && shoesList.size() > 0) {
session.setAttribute("shoes_list", shoesList);
}
System.out.println(shoesList.size());
if (request.getParameter("user") != null) {
return "admin_shoes_list";
}
return "shoes_list";
}
public String queryShoesById() {
int sid = Integer.valueOf(request.getParameter("sid"));
System.out.println("sid"+sid);
Shoes s = shoesDao.getShoesById(sid);
session.setAttribute("shoes_detial", s);
List<Evaluation> allEvaluations = new ArrayList<Evaluation>();
List<OrderShoes> orderShoes = orderShoesDao.queryOrderByShoes(sid);
for(OrderShoes os:orderShoes){
List<Evaluation> evaluations = evaluationDao.queryEvaluationByOidUserInShoesDetial(os.getOid());
allEvaluations.addAll(evaluations);
}
//System.out.println(allEvaluations.get(0).getOrderShoes().getClient().getNickName());
session.setAttribute("allEvaluations", allEvaluations);
if (request.getParameter("fuction").equals("update")) {
return "admin_shoes_detial";
}else {
return "shoes_detial";
}
}
public String jumpEvaluation() {
int oid = Integer.valueOf(request.getParameter("eOId"));
Evaluation evaluation = evaluationDao.queryEvaluationByOid(oid);
if (evaluation!=null) {
session.setAttribute("evaluation",evaluation);
return "browser_evaluation_succuss";
}
session.setAttribute("eOId", oid);
return "jumpEvaluation_success";
}
public String insertEvaluation() throws Exception {
int oid = (Integer) session.getAttribute("eOId");
OrderShoes orderShoes = orderShoesDao.queryOrderByOid(oid);
System.out.println(oid);
String pathString = evaluationPhoto.uploadPhoto("evalue");
evaluation.setOrderShoes(orderShoes);
evaluation.setEvaluePicturePath(pathString);
evaluationDao.saveEvaluation(evaluation);
return "evalue_success";
}
public String insertShoes() throws Exception {
System.out.println(brand.getBid());
brand = shoesDao.queryBrandById(brand.getBid());
shoes.setBrand(brand);
String smallPicturePath = smallPhoto.uploadPhoto("shoesSmall");
String bigPicturePath = bigPhoto.uploadPhoto("shoesBig");
shoes.setBigPicturePath(bigPicturePath);
shoes.setSmallPicturePath(smallPicturePath);
shoesDao.saveShoes(shoes);
List<Shoes> shoess = (List<Shoes>) session.getAttribute("shoes_list");
if (shoess==null) {
shoess=new ArrayList<Shoes>();
}
shoess.add(shoes);
session.setAttribute("shoes_list", shoess);
return "shoes_insert";
}
public String showGenderShoes() {
String gender = request.getParameter("gender");
if (gender.equals("boy")) {
gender = "男";
} else {
gender = "女";
}
List<Shoes> shoesGenderList = shoesDao.queryShoesByGender(gender);
session.setAttribute("shoes_gender_list", shoesGenderList);
return "shoes_gender";
}
public String updateShoes() throws Exception {
Shoes s = (Shoes) session.getAttribute("shoes_detial");
shoes.setSid(s.getSid());
if (smallPhoto != null) {
String smallPicturePath = smallPhoto.uploadPhoto("shoesSmall");
shoes.setSmallPicturePath(smallPicturePath);
} else {
shoes.setSmallPicturePath(s.getSmallPicturePath());
}
if (bigPhoto != null) {
String bigPicturePath = bigPhoto.uploadPhoto("shoesBig");
shoes.setBigPicturePath(bigPicturePath);
} else {
shoes.setBigPicturePath(s.getBigPicturePath());
}
shoesDao.updateShoes(shoes);
return "shoes_update";
}
public String insertBrand() throws Exception {
System.out.println("调用");
//System.out.println("photo"+brandPhoto);
//String str = brandPhoto.uploadPhoto("brand");
//brand.setBrandPhoto(str);
shoesDao.saveBrand(brand);
return "brand_save_success";
}
public String queryAllBrand() {
List<Brand> brands = shoesDao.queryAllBrand();
System.out.println(brands.size());
System.out.println(brands.get(0).getBcname());
session.setAttribute("brand_list", brands);
return "brand_query_success";
}
public String addShoppingCar() {
int tempShoesNum = Integer
.valueOf(request.getParameter("tempShoesNum"));
System.out.println(tempShoesNum);
if (session.getAttribute("online_client") == null) {
return "add_shopingcar_faliure";
}
if (session.getAttribute("shoppingcar") == null) {
shoppingCarShoes = new ArrayList<OrderShoes>();
} else {
shoppingCarShoes = (List<OrderShoes>) session
.getAttribute("shoppingcar");
}
Shoes shoes = (Shoes) session.getAttribute("shoes_detial");
OrderShoes shoesBuy = new OrderShoes();
shoesBuy.setNum(tempShoesNum);
shoesBuy.setShoes(shoes);
System.out.println(shoesBuy.getNum());
shoesBuy.setPayment(tempShoesNum * shoes.getPrice());
System.out.print
s2shDemo.rar
需积分: 0 25 浏览量
更新于2023-11-10
收藏 124.3MB RAR 举报
【s2shDemo.rar】是一个压缩包,包含了一个基于JSP技术开发的项目实例,名为"S2SH Demo"。S2SH是Struts、Spring和Hibernate三个开源框架的缩写,这是一种常见的Java Web应用程序开发模式。这个项目可以作为学习、实践或者进行毕业设计或课程设计的参考。
1. **Struts**:这是一个MVC(Model-View-Controller)框架,负责处理用户请求并将其映射到相应的业务逻辑。在S2SH中,Struts负责控制流程,定义了动作和结果,使开发者能够清晰地分离视图层和控制层。
2. **Spring**:Spring框架提供了全面的依赖注入(DI)和面向切面编程(AOP)功能,便于管理和配置应用中的对象。它还包含了Spring MVC,是Web层的一个轻量级解决方案,与Struts类似,但提供了更多的灵活性和控制力。
3. **Hibernate**:这是一个强大的对象关系映射(ORM)工具,使得Java开发者可以方便地操作数据库。通过Hibernate,我们可以用Java对象来代表数据库中的记录,简化了数据操作和事务管理。
4. **JSP(JavaServer Pages)**:JSP是Java EE的一部分,主要用于创建动态网页。它将HTML代码和Java代码结合在一起,允许在服务器端生成HTML,并发送到客户端浏览器显示。在S2SH项目中,JSP通常用于构建视图层,展示由控制器处理后的数据。
5. **学习和实践**:对于初学者,S2SHDemo项目提供了一个实际的平台,可以学习如何集成这三个框架,理解它们之间的交互,以及如何使用它们来构建一个完整的Web应用程序。同时,这个项目还可以作为基础,根据需求进行扩展或修改,适应不同的毕业设计或课程设计需求。
6. **毕业设计和课程设计**:在毕业设计或课程设计中,这样的项目可以帮助学生掌握企业级应用开发的基本流程,包括需求分析、设计、编码、测试和部署等环节。通过实际操作,学生可以提升问题解决能力和团队协作技能。
7. **文件结构**:虽然没有提供具体的子文件名,但通常一个S2SH项目会包含以下部分:`struts-config.xml`(Struts配置文件)、`spring-context.xml`(Spring配置文件)、`hibernate.cfg.xml`(Hibernate配置文件)、JSP页面、Java源代码(包括Action类、Service类、DAO类等)、数据库脚本等。
s2shDemo.rar中的项目是一个综合性的学习资源,涵盖了Java Web开发的核心技术,对于想要深入理解和实践这些技术的开发者来说,这是一个宝贵的实践平台。通过深入研究和改造这个项目,可以提升开发者在Web应用开发领域的专业技能。