📄 roleaction.java
字号:
/**
*
*/
package com.lily.dap.webapp.action.right;
import java.util.List;
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.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import com.lily.dap.model.QueryCondition;
import com.lily.dap.model.right.Role;
import com.lily.dap.service.core.exception.DataContentRepeatException;
import com.lily.dap.service.right.RoleManager;
import com.lily.dap.webapp.action.AbstractAction;
import com.lily.dap.webapp.util.ParamUtils;
/**
* @author zouxuemo
*
* 实现对Role对象进行CRUD操作的Action类
*/
public class RoleAction extends AbstractAction {
private RoleManager roleManager;
/**
* @param roleManager 要设置的 roleManager
*/
public void setRoleManager(RoleManager roleManager) {
this.roleManager = roleManager;
}
public ActionForward add(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("构造RoleForm,进入Role编辑页面");
}
Role role = new Role();
role.setDes("角色说明");
bindForm(form, role);
return mapping.findForward("edit");
}
public ActionForward edit(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("修改RoleForm,进入Role编辑页面");
}
long id = ParamUtils.getLongParameter(request, "id", 0);
Role role = (Role)roleManager.get(Role.class, id);
bindForm(form, role);
return mapping.findForward("edit");
}
public ActionForward save(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("保存WorkEvaluateTempletForm");
}
ActionMessages errors = form.validate(mapping, request);
Role role = new Role();
bindObject(form, role);
if (role.getId() > 0)
roleManager.modifyRole(role.getId(), role.getName(), role.getDes());
else {
try {
role = roleManager.createPublicRole(role.getCode(), role.getName(), role.getDes());
} catch (DataContentRepeatException ex) {
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("role.errors.repeat"));
saveErrors(request, errors);
return mapping.findForward("edit");
}
}
StringBuffer sb = new StringBuffer();
sb.append("<script type=\"text/javascript\">");
sb.append("alert(\"保存成功!\");window.close(); window.opener.location.reload();");
sb.append("</script>");
renderHtml(response, sb.toString());
return null;
}
public ActionForward remove(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("删除Role对象");
}
String[] ids = ParamUtils.getParameter(request, "ids").split(",");
for(int i = 0; i < ids.length; i++){
if(!ids[i].equals("")){
long id = Long.parseLong(ids[i]);
roleManager.removeRole(id);
}
}
return mapping.findForward("actionList");
}
public ActionForward detail(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("显示/打印Role");
}
long id = ParamUtils.getLongParameter(request, "id", 0);
Role role = (Role)roleManager.get(Role.class, id);
bindForm(form, role);
return mapping.findForward("detail");
}
public ActionForward list(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("查询显示Role列表");
}
QueryCondition queryCondition = new QueryCondition();
queryCondition.addOrder("code"); //初始的排序方法
List roleList = roleManager.gets(Role.class, queryCondition);
request.setAttribute("roleList", roleList);
return mapping.findForward("list");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -