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

📄 categoryopeaction.java

📁 struts hibernate框架 商场买卖
💻 JAVA
字号:
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.shopping.struts.action.category;

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.shopping.dao.UnifyDao;
import com.shopping.factory.DAOFactory;
import com.shopping.struts.form.CategoryOpeForm;
import com.shopping.vo.Category;

/** 
 * MyEclipse Struts
 * Creation date: 05-03-2008
 * 
 * XDoclet definition:
 * @struts.action path="/admin/categoryOpe" name="categoryOpeForm" input="/admin/categoryAdd.jsp" parameter="action" scope="request" validate="true"
 */
public class CategoryOpeAction extends DispatchAction {

	public ActionForward add(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		CategoryOpeForm categoryOpeForm = (CategoryOpeForm) form;// TODO Auto-generated method stub
		String name = categoryOpeForm.getName();
		String id = categoryOpeForm.getCate();
		UnifyDao catDao = null;
		try {
			catDao = (UnifyDao) DAOFactory.getBean("com.shopping.dao.imp.CatDaoImp");
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		int pid = Integer.parseInt(id);
		Category cate = new Category();
		cate.setName(name);
		cate.setPid(pid);
		
		if(catDao.insertTable(cate)){
			request.setAttribute("info", "success");
			return new ActionForward("/admin/categoryAdd.jsp");
		} else {
			request.setAttribute("info", "wrong");
			return new ActionForward("/admin/categoryAdd.jsp");
		}
	}
	
	public ActionForward modify(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		CategoryOpeForm categoryOpeForm = (CategoryOpeForm) form;// TODO Auto-generated method stub
		String name = categoryOpeForm.getName();
		String id = categoryOpeForm.getCate();
		int catId = Integer.parseInt(categoryOpeForm.getId());
		UnifyDao catDao = null;
		try {
			catDao = (UnifyDao) DAOFactory.getBean("com.shopping.dao.imp.CatDaoImp");
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		int pid = Integer.parseInt(id);
		Category cate = (Category)catDao.getTableById(catId);
		cate.setName(name);
		cate.setPid(pid);
		
		if(catDao.updateTable(cate)){
			request.setAttribute("info", "success");
			return new ActionForward("/admin/category.jsp");
		} else {
			request.setAttribute("info", "wrong");
			return new ActionForward("/admin/category.jsp");
		}
	}
	
	public ActionForward delete(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		UnifyDao catDao = null;
		try {
			catDao = (UnifyDao) DAOFactory.getBean("com.shopping.dao.imp.CatDaoImp");
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String id = request.getParameter("id");
		int catId = Integer.parseInt(id);
		Category cat = (Category) catDao.getTableById(catId);
		if(cat.getPid()==0){
			catDao.deleteTableById(catId);
			catDao.deleteTableByPid(catId);
			return new ActionForward("/admin/category.jsp");
		}
		else{
			catDao.deleteTableById(catId);
			return new ActionForward("/admin/category.jsp");
		}
		
	}
}

⌨️ 快捷键说明

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