package emp.shop.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import emp.shop.form.AddProductForm;
import emp.shop.idao.IProductDao;
import emp.shop.idao.IProductTypeDao;
import emp.shop.model.Product;
import emp.shop.model.ProductType;

public class AddProductAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		AddProductForm apf = (AddProductForm)form;
		
		ApplicationContext app = new ClassPathXmlApplicationContext("applicationContext-*.xml");
		IProductDao productDao = (IProductDao)app.getBean("productDaoProxy");
		IProductTypeDao productTypeDao = (IProductTypeDao)app.getBean("productTypeDaoProxy");
		Product product = (Product)app.getBean("product");
		ProductType productType = (ProductType)app.getBean("productType");
		
		BeanUtils.copyProperties(product, apf);
		product.setProduct_sale_count("0");
		product.setProduct_hit(0);
		
		productType = productTypeDao.queryProductTypeById(apf.getProduct_type_id());
		
		product.setProductType(productType);
		
		productDao.addProduct(product);
		
		return mapping.findForward("success");
	}

}
最近下载更多
要用魔法打败魔法  LV2 2021年12月20日
为了水掉6位用户名  LV4 2021年8月20日
giantinheart  LV3 2021年5月22日
a14628909  LV4 2021年5月13日
浴皇大帝  LV8 2021年3月20日
lsglsg9  LV22 2021年1月4日
ldy666  LV8 2020年12月8日
长安tianzhu2  LV3 2020年9月14日
pdd1234  LV2 2020年7月10日
1152857953  LV4 2020年6月17日
最近浏览更多
WBelong  LV7 2023年12月11日
3273408633  LV2 2023年9月14日
zzz10086 2023年6月15日
暂无贡献等级
2064749570 2023年5月25日
暂无贡献等级
彩色天空  LV5 2023年4月8日
dudu33 2022年12月31日
暂无贡献等级
小逸夜  LV4 2022年12月24日
gaokeji  LV2 2022年12月19日
upup996  LV6 2022年12月15日
1642172710  LV2 2022年12月13日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友