waresaveaction.java
来自「一个很好的网上商城系统」· Java 代码 · 共 104 行
JAVA
104 行
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.hb.shop.web.struts.action;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.validator.DynaValidatorForm;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.hb.shop.dao.WaresDAO;
import com.hb.shop.model.Wares;
import com.hb.shop.util.PageController;
import com.jspsmart.upload.*;
/**
* MyEclipse Struts
* Creation date: 10-14-2008
*
* XDoclet definition:
* @struts.action path="/wareSave" name="wareSaveForm" input="/JSP/manager/wareEdit.jsp" parameter="method" scope="request" validate="true"
*/
public class WareSaveAction extends DispatchAction {
ClassPathXmlApplicationContext act = new ClassPathXmlApplicationContext("applicationContext.xml");
WaresDAO wareDao = (WaresDAO) act.getBean("WaresDAO");
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws ServletException
* @throws SmartUploadException
* @throws IOException
*/
public ActionForward save(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SmartUploadException {
DynaValidatorForm f = (DynaValidatorForm) form;// TODO Auto-generated method stub
String wareId = request.getParameter("wareId").trim();
Wares tempWare = null;
String wareName = (String) f.get("wareName");
float warePrice = Float.parseFloat((String) f.get("warePrice"));
String wareState = (String) f.get("wareState");
String wareInfo = (String) f.get("wareInfo");
String warePhoto = ((String) f.get("warePhoto"));
String str[] = warePhoto.split("\\\\");
warePhoto = str[str.length-1];
/*
SmartUpload su = new SmartUpload();
su.initialize(this.getServlet().getServletConfig(), request, response);
su.upload();
int count = su.save("E:/photo");
*/
System.out.println(wareId+"---"+wareName+"---"+warePrice+"---"+wareState+"---"+wareInfo+warePhoto);
if(!wareId.equals("")){
tempWare = wareDao.findById(Integer.parseInt(wareId));
tempWare.setWareName(wareName);
tempWare.setWarePrice(warePrice);
tempWare.setWareState(wareState);
tempWare.setWareInfo(wareInfo);
if(!warePhoto.equals("")){
tempWare.setWarePhoto(warePhoto);
}
wareDao.attachDirty(tempWare);
}else{
tempWare = new Wares();
tempWare.setWareName(wareName);
tempWare.setWarePrice(warePrice);
tempWare.setWareState(wareState);
tempWare.setWareInfo(wareInfo);
tempWare.setWarePhoto(warePhoto);
tempWare.setWareDate(new java.util.Date());
wareDao.save(tempWare);
}
PageController waresList =new PageController();
List wares = wareDao.findAll();
waresList.setBigRecordSet((ArrayList) wares);
waresList.setCurrentPageIndex(1);
request.setAttribute("waresList", waresList);
return mapping.findForward("wareManage");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?