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

📄 rightsaction.java

📁 基于Sturts+Spring+Hibernate的一个高级销售管理系统。内容丰富
💻 JAVA
字号:
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.yuanchung.sales.struts.admin;

import java.io.IOException;
import java.io.PrintWriter;

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.yuanchung.sales.model.admin.Rights;
import com.yuanchung.sales.service.admin.rights.RightsMgr;
import com.yuanchung.sales.service.admin.rights.impl.RightsMgrImpl;

/** 
 * MyEclipse Struts
 * Creation date: 11-03-2008
 * 
 * XDoclet definition:
 * @struts.action path="/rights" name="rightsForm" input="/form/rights.jsp" parameter="dispatch" scope="request" validate="true"
 */
public class RightsAction extends DispatchAction {
	/*
	 * Generated Methods
	 */
	
	/** 
	 * 获取权限信息到权限管理页面
	 * Method toRightsManagePage
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward toRightsManagePage(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		String forward = "rightsManage";
		String rightsId = request.getParameter("rightsId");
		int id = 0;
		if(rightsId != null && !rightsId.equals("")){
			id = Integer.parseInt(rightsId);
		}
		try {
			Rights r = RightsMgrImpl.findById(id);
			request.setAttribute("rights", r);
		} catch (Exception e) {
			// TODO: handle exception
		}
		return mapping.findForward(forward);
	}
	
	/** 
	 * 操作权限
	 * Method toRightsManagePage
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws IOException 
	 */
	public ActionForward manipulateRights(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws IOException {
		String forward = "rightsManage";
		String rightsId = request.getParameter("rightsId");
		String rightsName = "";
		String type = request.getParameter("type");
		int id = 0;
		if(rightsId != null && !rightsId.equals("")){
			id = Integer.parseInt(rightsId);
		}
		try {
			Rights r = RightsMgrImpl.findById(id);
			if(type != null && type.equals("add")){
				rightsName = request.getParameter("addRightsName");
				Rights right = new Rights();
				right.setParentId(r.getId());
				right.setRightsName(rightsName);
				RightsMgrImpl.save(right);
				request.setAttribute("info", "修改权限名称成功!");
			}else if(type != null && type.equals("edit")){
				rightsName = request.getParameter("editRightsName");
				r.setRightsName(rightsName);
				RightsMgrImpl.update(r);
				request.setAttribute("info", "创建新权限成功!");
			}
			request.setAttribute("rights", r);
		} catch (Exception e) {
			// TODO: handle exception
		}
		return mapping.findForward(forward);
	}
	
	/** 
	 * 删除权限
	 * Method toRightsManagePage
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws IOException 
	 */
	public ActionForward deleteRights(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws IOException {
		String message = "";
		String rightsId = request.getParameter("rightsId");
		int id = 0;
		if(rightsId != null && !rightsId.equals("")){
			id = Integer.parseInt(rightsId);
		}
		Rights r = new Rights();
		try {
			r = RightsMgrImpl.findById(id);//获取对象
			//根据ID删除权限记录包括子权限
			RightsMgrImpl.delIncChildRightsById(r.getId());
			message = "删除权限 [" + r.getRightsName() + "] 成功!";
		} catch (Exception e) {
			message = "删除权限 [" + r.getRightsName() + "] 失败!";
		}
		PrintWriter out = response.getWriter();
		out.print("<script>");
		out.print("window.opener.location.reload();");
		out.print("window.close();");
		out.print("</script>");
		return null;
	}
}

⌨️ 快捷键说明

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