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

📄 productsaction.java

📁 java game java game
💻 JAVA
字号:
package com.game.products.web.actions;

import java.util.List;

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 com.game.commons.Pager;
import com.game.commons.PagerService;
import com.game.products.model.Products;
import com.game.products.services.ProductsService;
import com.game.products.web.forms.ProductsForm;


public class ProductsAction extends DispatchAction {
	
	private ProductsService productsService;
	private PagerService pagerService;
	
	/** 
	 * 显示所有信息
	 */
	public ActionForward doGetProducts(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest req,
			HttpServletResponse res){
		String flag=req.getParameter("flag");
		
		int totalRows=productsService.getRows();
		String currentPage=req.getParameter("currentPage");
		String pagerMethod=req.getParameter("pagerMethod");
		
		Pager pager=pagerService.getPager(currentPage, pagerMethod, totalRows);
		
		List productsList=productsService.getProducts(pager.getPageSize(), pager.getStartRow());
		
		req.setAttribute("productsList", productsList);
		req.setAttribute("PAGER", pager);
		req.setAttribute("flag", flag);
		req.setAttribute("totalRows", String.valueOf(totalRows));
		
		return mapping.findForward("all");
	}
	
	/** 
	 * 显示一条信息
	 */
	public ActionForward doGetProduct(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest req,
			HttpServletResponse res){
		String flag=req.getParameter("flag");
		String gameId=req.getParameter("gameId");
		String fieldname="";
		String value="";
		if(flag.equals("2")){
			fieldname=(String)req.getParameter("fieldname");
			value=(String)req.getParameter("value");
			req.setAttribute("fieldname", fieldname);
			req.setAttribute("value", value);
		}
		
		Products pd=productsService.getProduct(gameId);
		req.setAttribute("pd", pd);
		req.setAttribute("flag", flag);
		return mapping.findForward("one");
	}
	
	/** 
	 * 添加信息页面
	 */
	public ActionForward doAddProductPage(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest req,
			HttpServletResponse res){
		String flag=req.getParameter("flag");
		req.setAttribute("flag", flag);
		String fieldname="";
		String value="";
		if(flag.equals("2")){
			fieldname=(String)req.getParameter("fieldname");
			value=(String)req.getParameter("value");
			req.setAttribute("fieldname", fieldname);
			req.setAttribute("value", value);
		}
		
		String maxid=productsService.getMaxID();
		req.setAttribute("maxid", maxid);
		return mapping.findForward("add");
	}
	
	/** 
	 * 添加信息
	 */
	public ActionForward doAddProduct(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest req,
			HttpServletResponse res){
		ProductsForm pf=(ProductsForm)form;
		String flag=pf.getFlag();
		req.setAttribute("flag", flag);
		String fieldname="";
		String value="";
		if(flag.equals("2")){
			fieldname=pf.getFieldname();
			value=pf.getValue();
			req.setAttribute("fieldname", fieldname);
			req.setAttribute("value", value);
		}
		
		Products pd=new Products();
		pd.setGameCapacity(pf.getGameCapacity());
		pd.setGameId(pf.getGameId());
		pd.setGameMedia(pf.getGameMedia());
		pd.setGameNameCn(pf.getGameNameCn());
		pd.setGameNameEn(pf.getGameNameEn());
		pd.setGameVersion(pf.getGameVersion());
		pd.setGameCopyright(pf.getGameCopyright());
		pd.setGameContent(pf.getGameContent());
		if(pf.getGamePrice().equals("")){
			pd.setGamePrice(null);
		}else{
			pd.setGamePrice(pf.getGamePrice());
		}
		
		int sign=1;
		try{
			productsService.addProduct(pd);
			sign=1;
		}catch(Exception e){
			sign=2;
		}
		
		if(sign==1){
			return mapping.findForward("success");
		}else{
			return mapping.findForward("failure");
		}
	}
	
	/** 
	 * 修改信息
	 */
	public ActionForward doUpdateProduct(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest req,
			HttpServletResponse res){
		ProductsForm pf=(ProductsForm)form;
		String gameId=pf.getGameId();
		
		String flag=pf.getFlag();
		req.setAttribute("flag", flag);
		String fieldname="";
		String value="";
		if(flag.equals("2")){
			fieldname=pf.getFieldname();
			value=pf.getValue();
			req.setAttribute("fieldname", fieldname);
			req.setAttribute("value", value);
		}
		
		Products pd=productsService.getProduct(gameId);
		pd.setGameCapacity(pf.getGameCapacity());
		pd.setGameId(pf.getGameId());
		pd.setGameMedia(pf.getGameMedia());
		pd.setGameNameCn(pf.getGameNameCn());
		pd.setGameNameEn(pf.getGameNameEn());
		pd.setGameVersion(pf.getGameVersion());
		pd.setGameCopyright(pf.getGameCopyright());
		pd.setGameContent(pf.getGameContent());
		if(pf.getGamePrice().equals("")){
			pd.setGamePrice(null);
		}else{
			pd.setGamePrice(pf.getGamePrice());
		}
		
		int sign=1;
		try{
			productsService.updateProductd(pd);
			sign=1;
		}catch(Exception e){
			sign=2;
		}
		
		if(sign==1){
			return mapping.findForward("success");
		}else{
			return mapping.findForward("failure");
		}
	}
	
	/** 
	 * 删除信息
	 */
	public ActionForward doDeleteProduct(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest req,
			HttpServletResponse res){
		String flag=req.getParameter("flag");
		req.setAttribute("flag", flag);
		String fieldname="";
		String value="";
		if(flag.equals("2")){
			fieldname=(String)req.getParameter("fieldname");
			value=(String)req.getParameter("value");
			req.setAttribute("fieldname", fieldname);
			req.setAttribute("value", value);
		}
		
		String gameId=req.getParameter("gameId");
		Products pd=productsService.getProduct(gameId);
		int sign=1;
		try{
			productsService.deleteProduct(pd);
			sign=1;
		}catch(Exception e){
			sign=2;
		}
		
		if(sign==1){
			return mapping.findForward("success");
		}else{
			return mapping.findForward("failure");
		}
	}
	
	/** 
	 * 返回信息
	 */
	public ActionForward doReturnProduct(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest req,
			HttpServletResponse res){
		String flag=req.getParameter("flag");
		req.setAttribute("flag", flag);
		String fieldname="";
		String value="";
		if(flag.equals("1")){
			int totalRows=productsService.getRows();
			String currentPage=req.getParameter("currentPage");
			String pagerMethod=req.getParameter("pagerMethod");
			
			Pager pager=pagerService.getPager(currentPage, pagerMethod, totalRows);
			
			List productsList=productsService.getProducts(pager.getPageSize(), pager.getStartRow());
			
			req.setAttribute("productsList", productsList);
			req.setAttribute("PAGER", pager);
			req.setAttribute("flag", flag);
			req.setAttribute("totalRows", String.valueOf(totalRows));
		}else if(flag.equals("2")){
			fieldname=(String)req.getParameter("fieldname");
			value=(String)req.getParameter("value");
			int totalRows=productsService.getRows(fieldname,value);
			String currentPage=req.getParameter("currentPage");
			String pagerMethod=req.getParameter("pagerMethod");
			
			Pager pager=pagerService.getPager(currentPage, pagerMethod, totalRows);

			req.setAttribute("fieldname", fieldname);
			req.setAttribute("value", value);
			
			List productsList=productsService.queryProducts(fieldname, value,pager.getPageSize(), pager.getStartRow());
			
			req.setAttribute("productsList", productsList);
			req.setAttribute("PAGER", pager);
			req.setAttribute("totalRows", String.valueOf(totalRows));
		}
		
		return mapping.findForward("all");
		
	}
	
	/** 
	 * 查询信息
	 */
	public ActionForward doQueryProduct(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest req,
			HttpServletResponse res){
		String flag=req.getParameter("flag");
		req.setAttribute("flag", flag);
		String fieldname="";
		String value="";
		fieldname=(String)req.getParameter("fieldname");
		value=(String)req.getParameter("value");
		
		int totalRows=productsService.getRows(fieldname,value);
		String currentPage=req.getParameter("currentPage");
		String pagerMethod=req.getParameter("pagerMethod");
		
		Pager pager=pagerService.getPager(currentPage, pagerMethod, totalRows);

		req.setAttribute("fieldname", fieldname);
		req.setAttribute("value", value);
		
		List productsList=productsService.queryProducts(fieldname, value,pager.getPageSize(), pager.getStartRow());
		
		req.setAttribute("productsList", productsList);
		req.setAttribute("PAGER", pager);
		req.setAttribute("totalRows", String.valueOf(totalRows));
		
		return mapping.findForward("all");
		
	}

	public ProductsService getProductsService() {
		return productsService;
	}

	public void setProductsService(ProductsService productsService) {
		this.productsService = productsService;
	}

	public PagerService getPagerService() {
		return pagerService;
	}

	public void setPagerService(PagerService pagerService) {
		this.pagerService = pagerService;
	}
	
}

⌨️ 快捷键说明

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