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