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

📄 privilegegroupmanageaction.java

📁 巴巴运动网源码 传智博客出品 不全 一部分代码 可以参考
💻 JAVA
字号:
package com.itcast.web.action.privilege;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.annotation.Resource;
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.springframework.stereotype.Controller;

import com.itcast.bean.privilege.PrivilegeGroup;
import com.itcast.bean.privilege.SystemPrivilege;
import com.itcast.bean.privilege.SystemPrivilegePK;
import com.itcast.service.privilege.PrivilegeGroupService;
import com.itcast.service.privilege.SystemPrivilegeService;
import com.itcast.utils.SiteUrl;
import com.itcast.web.formbean.privilege.PrivilegeGroupForm;

@Controller("/control/privilegegroup/manage")
public class PrivilegeGroupManageAction extends DispatchAction {
	@Resource(name="privilegeGroupServiceBean") private PrivilegeGroupService privilegeGroupService;
	@Resource(name="systemPrivilegeServiceBean") private SystemPrivilegeService systemPrivilegeService;
	
	/**
	 * 权限组添加界面
	 */
	@Privilege(model="privilegegroup", privilegeValue="insert")
	public ActionForward addUI(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		request.setAttribute("privileges", systemPrivilegeService.getScrollData(SystemPrivilege.class).getResultlist());
		return mapping.findForward("add");
	}
	/**
	 * 权限组添加
	 */
	@Privilege(model="privilegegroup", privilegeValue="insert")
	public ActionForward add(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		PrivilegeGroupForm formbean = (PrivilegeGroupForm)form;
		PrivilegeGroup privilegeGroup = new PrivilegeGroup(formbean.getName());
		for(SystemPrivilegePK pk : formbean.getPrivileges()){
			privilegeGroup.addPrivilege(new SystemPrivilege(pk));
		}
		privilegeGroupService.save(privilegeGroup);
		request.setAttribute("message", "权限组添加成功");
		request.setAttribute("urladdress", SiteUrl.readUrl("control.privilegegroup.list"));
		return mapping.findForward("message");
	}
	
	/**
	 * 权限组修改界面
	 */
	@Privilege(model="privilegegroup", privilegeValue="update")
	public ActionForward editUI(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		PrivilegeGroupForm formbean = (PrivilegeGroupForm)form;
		PrivilegeGroup privilegeGroup = privilegeGroupService.find(PrivilegeGroup.class, formbean.getGroupid());
		formbean.setName(privilegeGroup.getName());
		request.setAttribute("selectprivileges", privilegeGroup.getPrivileges());
		request.setAttribute("privileges", systemPrivilegeService.getScrollData(SystemPrivilege.class).getResultlist());
		return mapping.findForward("edit");
	}
	
	/**
	 * 权限组修改
	 */
	@Privilege(model="privilegegroup", privilegeValue="update")
	public ActionForward edit(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		PrivilegeGroupForm formbean = (PrivilegeGroupForm)form;
		PrivilegeGroup privilegeGroup = privilegeGroupService.find(PrivilegeGroup.class, formbean.getGroupid());
		privilegeGroup.setName(formbean.getName());
		List<SystemPrivilege> deletes = new ArrayList<SystemPrivilege>();
		List<SystemPrivilegePK> pks = Arrays.asList(formbean.getPrivileges());
		for(SystemPrivilege p : privilegeGroup.getPrivileges()){
			if(!pks.contains(p.getId())) deletes.add(p);
		}
		privilegeGroup.getPrivileges().removeAll(deletes);
		for(SystemPrivilegePK pk : formbean.getPrivileges()){
			SystemPrivilege systemPrivilege = new SystemPrivilege(pk);
			if(!privilegeGroup.getPrivileges().contains(systemPrivilege)){
				privilegeGroup.addPrivilege(systemPrivilege);
			}
		}
		privilegeGroupService.update(privilegeGroup);
		request.setAttribute("message", "权限组修改成功");
		request.setAttribute("urladdress", SiteUrl.readUrl("control.privilegegroup.list"));
		return mapping.findForward("message");
	}
	
	
	/**
	 * 权限组删除
	 */
	@Privilege(model="privilegegroup", privilegeValue="delete")
	public ActionForward delete(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		PrivilegeGroupForm formbean = (PrivilegeGroupForm)form;
		privilegeGroupService.delete(PrivilegeGroup.class, formbean.getGroupid());
		request.setAttribute("message", "权限组删除成功");
		request.setAttribute("urladdress", SiteUrl.readUrl("control.privilegegroup.list"));
		return mapping.findForward("message");
	}
}

⌨️ 快捷键说明

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