OA项目之权限设计②

1.接着昨天的今天到了设计如何成功的实现权限分配的功能,首先我们看下这些功能的步骤如下图:

     首先是从user的list页面看到设置权限的按钮,点击进去进入设置权限的页面


   进入设置权限页面,看到的是权限的数据如下图:


分析这其中有几个请求:点击设置权限进入权限页面,这都是在Role的Action中做的跟他的修改感觉差不多,但是需要注意的是从设置权限进入到分配权限传递的是id,进入页面后我们需要回显,并且将所有的权限数据都显示在分配权限的页面中,这都是要准备的。下面就在RoleAction中添加2个方法代码如下:

package com.icss.oa.view.action;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.icss.oa.base.BaseAction;
import com.icss.oa.domain.Privilege;
import com.icss.oa.domain.Role;
import com.icss.oa.service.PrivilegeService;
import com.icss.oa.service.RoleService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

@SuppressWarnings("serial")
@Controller
@Scope("prototype")
public class RoleAction extends BaseAction<Role>  {
      
	  private Long[] privilegeIds;


		public Long[] getPrivilegeIds() {
		return privilegeIds;
	}

	public void setPrivilegeIds(Long[] privilegeIds) {
		this.privilegeIds = privilegeIds;
	}

		//列表方法
	    public String list() throws Exception {
		   List<Role>  roleList = roleService.findAll();
		   ActionContext.getContext().put("roleList", roleList);
		    return "list";
	    }
	
	    //删除方法
		public String delete() throws Exception {
			roleService.delete(model.getId());
			
			return "toList";
		}

		
		
		//增加页面方法
		public String addUI() throws Exception {
			
			return "addUI";
		}
		
		//增加方法
		public String add() throws Exception {
			//为页面参数设值
			// Role role=new Role();
			//role.setName(role.getName());
			//role.setDescription(role.getDescription());
			//保存到数据库
			roleService.save(model);
			return "toList";
		}
		
		//修改页面方法
		public String editUI() throws Exception {
			  //根据id得到role对象的一条信息并显示
			  Role  role1 = roleService.getById(model.getId());
			  //在edit页面显示数据
			  //this.name=role.getName();
			  //this.description=role.getDescription();
			ActionContext.getContext().getValueStack().push(role1);
			return "editUI";
		}
		
		//修改方法
		public String edit() throws Exception {
			//设置需要修改的值
		Role role2=	roleService.getById(model.getId());
		role2.setName(model.getName());
		role2.setDescription(model.getDescription());
			//update到数据库中
		roleService.update(role2);
			return "toList";
		}

		 //设置权限页面方法
	     public String setPrivilegeUI() throws Exception {
	    	 //准备回显的数据
	    	 
	    	 //准备显示的数据
	    	 Role role=roleService.getById(model.getId());
	    	 ActionContext.getContext().put("role", role);
	    	 List<Privilege> privilegeList=privilegeService.findAll();
	    	 ActionContext.getContext().put("privilegeList", privilegeList);
					  
			return "setPrivilegeUI";
		}
				
		//设置权限方法
		pub
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值