📄 useraction.java
字号:
package com.bjsxt.oa.web.actions;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.bjsxt.oa.managers.PersonManager;
import com.bjsxt.oa.managers.RoleManager;
import com.bjsxt.oa.managers.UserManager;
import com.bjsxt.oa.model.User;
import com.bjsxt.oa.web.forms.UserActionForm;
public class UserAction extends BaseAction {
private PersonManager personManager;
private UserManager userManager;
private RoleManager roleManager;
protected ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
//查找人员列表,以便给人员分配或删除登录帐号
request.setAttribute("pm", personManager.searchPersons());
return mapping.findForward("index");
}
//打开添加帐号界面
public ActionForward addInput(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
return mapping.findForward("add_input");
}
//添加用户帐号
public ActionForward add(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
UserActionForm uaf = (UserActionForm)form;
User user = new User();
BeanUtils.copyProperties(user, uaf);
userManager.addUser(user, uaf.getPersonId());
return mapping.findForward("pub_add_success");
}
//删除用户帐号
public ActionForward del(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
UserActionForm uaf = (UserActionForm)form;
userManager.delUser(uaf.getId());
return mapping.findForward("pub_del_success");
}
//查看被分配给用户的角色列表,在这个列表上,可以添加、删除被分配给用户的角色
public ActionForward searchUserRoles(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
UserActionForm uaf = (UserActionForm)form;
//在界面上提示,将要给XXX分配角色,所以需要加载User对象传递到界面上
request.setAttribute("user", userManager.findUser(uaf.getId()));
//搜索用户拥有的角色列表
request.setAttribute("urs", userManager.searchUserRoles(uaf.getId()));
return mapping.findForward("user_roles");
}
public ActionForward delUserRole(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
UserActionForm uaf = (UserActionForm)form;
int userId = uaf.getId();
int roleId = uaf.getRid();
userManager.delUserRole(userId, roleId);
return mapping.findForward("pub_del_success");
}
//添加或更新用户角色的输入界面,即在这个界面上可以选择某个角色来分配给用户
public ActionForward addOrUpdateUserRoleInput(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
request.setAttribute("pm", roleManager.searchRoles());
return mapping.findForward("user_role_input");
}
//添加或更新用户的角色
public ActionForward addOrUpdateUserRole(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
UserActionForm uaf = (UserActionForm)form;
int userId = uaf.getId();
int roleId = uaf.getRid();
int orderNo = uaf.getOrderNo();
userManager.addOrUpdateUserRole(userId, roleId, orderNo);
return mapping.findForward("pub_update_success");
}
public void setPersonManager(PersonManager personManager) {
this.personManager = personManager;
}
public void setUserManager(UserManager userManager) {
this.userManager = userManager;
}
public void setRoleManager(RoleManager roleManager) {
this.roleManager = roleManager;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -