首页>代码>基于SSH框架的java CRM客户关系管理系统,网上下载的模板>/crmmanager7 (1)/src/edu/cdio/action/RoleAction.java
package edu.cdio.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import edu.cdio.domain.Role;

import edu.cdio.service.RoleService;
import edu.cdio.util.PageBean;

@Controller		//����ע��spring�����е�roleAction
public class RoleAction extends ActionSupport implements ModelDriven<Role>{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Autowired 		//ע��roleService�ӿ�
	private RoleService roleService;
	//��װ���
	private Role role = new Role();
	public Role getModel() {
		return this.role;
	}
	
	private PageBean pageBean;
    private int pageNum =1;		//��ʾ��ҳ�з��صĵ�ǰ��ֵ��Ĭ��Ϊ1
	
	//ʵ�ַ�ҳ����
	public String page(){
		HttpServletRequest request=ServletActionContext.getRequest();
		String skipPage = request.getParameter("skipPage");
		//��תҳ�������Ƿ�Ϊ��

		if(skipPage!=null && !skipPage.equals("")){
			pageNum = Integer.parseInt(request.getParameter("skipPage"));
		}
		
	   this.pageBean = roleService.pageOfRole(5, pageNum);
	 
		ActionContext context = ActionContext.getContext();
	
		context.getSession().put("roleCount", pageBean.getCount());
		
		context.getSession().put("totalPage3", pageBean.getTotalPage());
		
		context.getSession().put("currentPage3", pageBean.getCurrentPage());
		context.getSession().put("listRole", pageBean.getList());
		return "page";
	}
	
	//���
		public String add(){
			ActionContext context = ActionContext.getContext();
			context.getSession().remove("msg");
			
			//��ȡ����
			HttpServletRequest request=ServletActionContext.getRequest();
			String name = role.getRolename();
			if (this.roleService.findOneRole(name).size()>0) {
				context.getSession().put("msg", "�û����Ѵ��ڣ�");
				return "errorAdd";
			}
             //ִ�з���
				this.roleService.saveRole(role);
				//������ʾ
				HttpServletResponse response = ServletActionContext.getResponse();
				response.setContentType("text/html;charset=utf-8");
				response.setCharacterEncoding("utf-8");
				
				try {
					PrintWriter out = response.getWriter();
				
					out.println("<script type='text/javascript'>alert('��ӳɹ���');"
							+ "window.location.href='roleAction_page';</script>");
					
					out.flush();
					out.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
				return null;
			}
		
		
	//��תҳ��
		public String skipAdd(){
			ActionContext context = ActionContext.getContext();
			context.getSession().remove("msg");
			context.getSession().remove("msg1");
			return "skipAdd";
		}
	
	//ɾ��
		public String delete(){
			
			this.roleService.deleteUser(role.getRoleid());
			return "delete";
		}
		//����һ���û���Ϣ
		public String show(){
			role = this.roleService.findOneRole(role.getRolename()).get(0);
			ActionContext context = ActionContext.getContext();
			context.getSession().put("role", role);
			return "show";
		}
		
		//�޸���Ϣ
		public String update() throws IOException{
			
			this.roleService.update(role);
			return "update";
		}
		//������ֹؼ�������
		public String select(){
			//��ȡ��������
			HttpServletRequest request=ServletActionContext.getRequest();
			String input = request.getParameter("search");
			String skipPage = request.getParameter("skipPage");
			//��תҳ�������Ƿ��
			if(skipPage!=null && !skipPage.equals("")){
				pageNum = Integer.parseInt(request.getParameter("skipPage"));
			}
			//ִ�з���
			pageBean = this.roleService.pageOfName(5, pageNum, input);
			ActionContext context = ActionContext.getContext();
			context.getSession().put("roleCount2", pageBean.getCount());
			context.getSession().put("totalPage2", pageBean.getTotalPage());
			context.getSession().put("currentPage2", pageBean.getCurrentPage());
			context.getSession().put("listRole2", pageBean.getList());
			return "select";
		}
		
	
}
最近下载更多
晴风8815  LV2 2023年2月27日
彭斌java  LV6 2022年12月1日
暮江吟  LV8 2022年11月12日
lwp011  LV27 2022年9月19日
gangan85  LV2 2022年8月1日
adminadminsqwqe  LV8 2022年7月13日
xiaohe229  LV8 2022年5月19日
wangyang520  LV6 2022年4月29日
安东尼online  LV11 2022年4月24日
杨豫川  LV12 2022年4月12日
最近浏览更多
15579993019  LV2 8月6日
Solowen 4月16日
暂无贡献等级
hawkzl  LV2 4月2日
cq1458824624 1月14日
暂无贡献等级
翰昌之杰2  LV6 2024年12月18日
张春青  LV6 2024年11月14日
sunlea  LV20 2024年5月22日
李俊雄  LV3 2024年4月30日
FFF112233  LV8 2024年3月27日
爱丽淇  LV5 2024年3月18日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友