基于javaweb+mysql的ssm公司员工管理系统(java+ssm+jsp+easyui+mysql)

基于javaweb+mysql的ssm公司员工管理系统(java+ssm+jsp+easyui+mysql)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb+mysql的SSM公司员工管理系统(java+ssm+jsp+easyui+mysql)

项目介绍

程序开发软件:IDEA/Eclipse/MyEclipse 数据库:mysql5.7

后台采用技术: SSM框架(SpringMVC + Spring + Mybatis) 前台采用技术: div + css + easyui框架

技术要点:

1 此系统采用了目前最流行的ssm框架,其中的spingMVC框架相对于struts2框架更灵活,更安全。 2 本项目springMVC框架采用了注解映射器,使用了RESTful风格的url对系统发起http请求,开发更灵活。 3 同时使用了了hibernate提供的校验框架,对客户端数据进行校验! 4 Mybati数据库DAO层采用的是Mapper代理开发方法,输入映射采用的是POJO包装类型实现,输出映射采用了resultMap类型,实现了数据库多对一映射。 5 spring容器内部使用拦截器,以Spring AOP的方式实现事务控制管理。

系统实体对象:

部门: 部门编号,部门名称 职位: 职位id,所属部门,职位名称,基本工资,销售提成

员工: 员工编号,职位,姓名,性别,员工照片,出生日期,学历,员工介绍

        	Position position = positionList.get(i); 
        	dataset.add(new String[]{position.getPositionId() + "",position.getDepartmentObj().getDepartmentName(),position.getPositionName(),position.getBaseSalary() + "",position.getSellPercent()});
        }
        /*
        OutputStream out = null;
		try {
			out = new FileOutputStream("C://output.xls");
			ex.exportExcel(title,headers, dataset, out);
		    out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		*/
		OutputStream out = null;//创建一个输出流对象 
		try { 
			out = response.getOutputStream();//
			response.setHeader("Content-disposition","attachment; filename="+"Position.xls");//filename是下载的xls的名,建议最好用英文 
			response.setContentType("application/msexcel;charset=UTF-8");//设置类型 
			response.setHeader("Pragma","No-cache");//设置头 
			response.setHeader("Cache-Control","no-cache");//设置头 
			response.setDateHeader("Expires", 0);//设置日期头  
			String rootPath = request.getSession().getServletContext().getRealPath("/");
			ex.exportExcel(rootPath,title,headers, dataset, out);
			out.flush();
		} catch (IOException e) { 
			e.printStackTrace(); 
		}finally{
			try{
				if(out!=null){ 
					out.close(); 
				}
			}catch(IOException e){ 
				e.printStackTrace(); 
			} 
		}
    }
}

	@RequestMapping(value = { "/OutToExcel" }, method = {RequestMethod.GET,RequestMethod.POST})
	public void OutToExcel(@ModelAttribute("departmentObj") Department departmentObj,String positionName, Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
        if(positionName == null) positionName = "";
        List<Position> positionList = positionService.queryPosition(departmentObj,positionName);
        ExportExcelUtil ex = new ExportExcelUtil();
        String title = "Position信息记录"; 
        String[] headers = { "职位id","所属部门","职位名称","基本工资","销售提成"};
        List<String[]> dataset = new ArrayList<String[]>(); 
        for(int i=0;i<positionList.size();i++) {
        	Position position = positionList.get(i); 
        	dataset.add(new String[]{position.getPositionId() + "",position.getDepartmentObj().getDepartmentName(),position.getPositionName(),position.getBaseSalary() + "",position.getSellPercent()});
        }
        /*
        OutputStream out = null;
		try {
			out = new FileOutputStream("C://output.xls");
			ex.exportExcel(title,headers, dataset, out);
		    out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		*/
		OutputStream out = null;//创建一个输出流对象 
		try { 
			out = response.getOutputStream();//
			response.setHeader("Content-disposition","attachment; filename="+"Position.xls");//filename是下载的xls的名,建议最好用英文 
			response.setContentType("application/msexcel;charset=UTF-8");//设置类型 
			response.setHeader("Pragma","No-cache");//设置头 
			response.setHeader("Cache-Control","no-cache");//设置头 
			response.setDateHeader("Expires", 0);//设置日期头  
			String rootPath = request.getSession().getServletContext().getRealPath("/");
			ex.exportExcel(rootPath,title,headers, dataset, out);
			out.flush();
		} catch (IOException e) { 
			e.printStackTrace(); 
		}finally{
			try{
				if(out!=null){ 
					out.close(); 
				}
			}catch(IOException e){ 
				e.printStackTrace(); 
			} 
		}
    }
}

		try {
			out = new FileOutputStream("C://output.xls");
			ex.exportExcel(title,headers, dataset, out);
		    out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		*/
		OutputStream out = null;//创建一个输出流对象 
		try { 
			out = response.getOutputStream();//
			response.setHeader("Content-disposition","attachment; filename="+"Employee.xls");//filename是下载的xls的名,建议最好用英文 
			response.setContentType("application/msexcel;charset=UTF-8");//设置类型 
			response.setHeader("Pragma","No-cache");//设置头 
			response.setHeader("Cache-Control","no-cache");//设置头 
			response.setDateHeader("Expires", 0);//设置日期头  
			String rootPath = request.getSession().getServletContext().getRealPath("/");
			ex.exportExcel(rootPath,title,headers, dataset, out);
			out.flush();
		} catch (IOException e) { 
			e.printStackTrace(); 
		}finally{
			try{
				if(out!=null){ 
					out.close(); 
				}
			}catch(IOException e){ 
				e.printStackTrace(); 
			} 
		}
    }
}

	@RequestMapping(value = { "/frontlist" }, method = {RequestMethod.GET,RequestMethod.POST})
	public String frontlist(String employeeNo,@ModelAttribute("positionObj") Position positionObj,String name,String birthday,Integer currentPage, Model model, HttpServletRequest request) throws Exception  {
		if (currentPage==null || currentPage == 0) currentPage = 1;
		if (employeeNo == null) employeeNo = "";
		if (name == null) name = "";
		if (birthday == null) birthday = "";
		List<Employee> employeeList = employeeService.queryEmployee(employeeNo, positionObj, name, birthday, currentPage);
	    /*计算总的页数和总的记录数*/
	    employeeService.queryTotalPageAndRecordNumber(employeeNo, positionObj, name, birthday);
	    /*获取到总的页码数目*/
	    int totalPage = employeeService.getTotalPage();
	    /*当前查询条件下总记录数*/
	    int recordNumber = employeeService.getRecordNumber();
	    request.setAttribute("employeeList",  employeeList);
	    request.setAttribute("totalPage", totalPage);
	    request.setAttribute("recordNumber", recordNumber);
	    request.setAttribute("currentPage", currentPage);
	    request.setAttribute("employeeNo", employeeNo);
	    request.setAttribute("positionObj", positionObj);
	    request.setAttribute("name", name);
	    request.setAttribute("birthday", birthday);
	    List<Position> positionList = positionService.queryAllPosition();
	    request.setAttribute("positionList", positionList);
		return "Employee/employee_frontquery_result"; 
	}

     /*前台查询Employee信息*/
	@RequestMapping(value="/{employeeNo}/frontshow",method=RequestMethod.GET)
	public String frontshow(@PathVariable String employeeNo,Model model,HttpServletRequest request) throws Exception {
		/*根据主键employeeNo获取Employee对象*/
        Employee employee = employeeService.getEmployee(employeeNo);

        List<Position> positionList = positionService.queryAllPosition();
        request.setAttribute("positionList", positionList);
        request.setAttribute("employee",  employee);
        return "Employee/employee_frontshow";
	}

	/*ajax方式显示员工修改jsp视图页*/
	@RequestMapping(value="/{employeeNo}/update",method=RequestMethod.GET)
	public void update(@PathVariable String employeeNo,Model model,HttpServletRequest request,HttpServletResponse response) throws Exception {
        /*根据主键employeeNo获取Employee对象*/
        Employee employee = employeeService.getEmployee(employeeNo);

        response.setContentType("text/json;charset=UTF-8");
        PrintWriter out = response.getWriter();
		//将要被返回到客户端的对象 
		JSONObject jsonEmployee = employee.getJsonObject();
		out.println(jsonEmployee.toString());
		out.flush();
		out.close();
	}

		if (br.hasErrors()) { 
			message = "输入的信息有错误!";
			writeJsonResponse(response, success, message);
			return;
		}
		try {
			positionService.updatePosition(position);
			message = "职位更新成功!";
			success = true;
			writeJsonResponse(response, success, message);
		} catch (Exception e) {
			e.printStackTrace();
			message = "职位更新失败!";
			writeJsonResponse(response, success, message); 
		}
	}
    /*删除职位信息*/
	@RequestMapping(value="/{positionId}/delete",method=RequestMethod.GET)
	public String delete(@PathVariable Integer positionId,HttpServletRequest request) throws UnsupportedEncodingException {
		  try {
			  positionService.deletePosition(positionId);
	            request.setAttribute("message", "职位删除成功!");
	            return "message";
	        } catch (Exception e) { 
	            e.printStackTrace();
	            request.setAttribute("error", "职位删除失败!");
				return "error";

	        }

	}

	/*ajax方式删除多条职位记录*/
	@RequestMapping(value="/deletes",method=RequestMethod.POST)
	public void delete(String positionIds,HttpServletRequest request,HttpServletResponse response) throws IOException, JSONException {
		String message = "";
    	boolean success = false;
        try { 
        	int count = positionService.deletePositions(positionIds);
        	success = true;
        	message = count + "条记录删除成功";
        	writeJsonResponse(response, success, message);
	            request.setAttribute("message", "职位删除成功!");
	            return "message";
	        } catch (Exception e) { 
	            e.printStackTrace();
	            request.setAttribute("error", "职位删除失败!");
				return "error";

	        }

	}

	/*ajax方式删除多条职位记录*/
	@RequestMapping(value="/deletes",method=RequestMethod.POST)
	public void delete(String positionIds,HttpServletRequest request,HttpServletResponse response) throws IOException, JSONException {
		String message = "";
    	boolean success = false;
        try { 
        	int count = positionService.deletePositions(positionIds);
        	success = true;
        	message = count + "条记录删除成功";
        	writeJsonResponse(response, success, message);
        } catch (Exception e) { 
            //e.printStackTrace();
            message = "有记录存在外键约束,删除失败";
            writeJsonResponse(response, success, message);
        }
	}

	/*按照查询条件导出职位信息到Excel*/
	@RequestMapping(value = { "/OutToExcel" }, method = {RequestMethod.GET,RequestMethod.POST})
	public void OutToExcel(@ModelAttribute("departmentObj") Department departmentObj,String positionName, Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
        if(positionName == null) positionName = "";
        List<Position> positionList = positionService.queryPosition(departmentObj,positionName);
        ExportExcelUtil ex = new ExportExcelUtil();
        String title = "Position信息记录"; 
        String[] headers = { "职位id","所属部门","职位名称","基本工资","销售提成"};
        List<String[]> dataset = new ArrayList<String[]>(); 
        for(int i=0;i<positionList.size();i++) {
        	Position position = positionList.get(i); 
        	dataset.add(new String[]{position.getPositionId() + "",position.getDepartmentObj().getDepartmentName(),position.getPositionName(),position.getBaseSalary() + "",position.getSellPercent()});
        }
        /*
        OutputStream out = null;
		try {
			out = new FileOutputStream("C://output.xls");
			ex.exportExcel(title,headers, dataset, out);
		    out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		*/
		OutputStream out = null;//创建一个输出流对象 
		try { 
	/*客户端ajax方式提交添加员工信息*/
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public void add(@Validated Employee employee, BindingResult br,
			Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
		String message = "";
		boolean success = false;
		if (br.hasErrors()) {
			message = "输入信息不符合要求!";
			writeJsonResponse(response, success, message);
			return ;
		}
		if(employeeService.getEmployee(employee.getEmployeeNo()) != null) {
			message = "员工编号已经存在!";
			writeJsonResponse(response, success, message);
			return ;
		}
		try {
			employee.setEmployeePhoto(this.handlePhotoUpload(request, "employeePhotoFile"));
		} catch(UserException ex) {
			message = "图片格式不正确!";
			writeJsonResponse(response, success, message);
			return ;
		}
        employeeService.addEmployee(employee);
        message = "员工添加成功!";
        success = true;
        writeJsonResponse(response, success, message);
	}
	/*ajax方式按照查询条件分页查询员工信息*/
	@RequestMapping(value = { "/list" }, method = {RequestMethod.GET,RequestMethod.POST})
	public void list(String employeeNo,@ModelAttribute("positionObj") Position positionObj,String name,String birthday,Integer page,Integer rows, Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
		if (page==null || page == 0) page = 1;
		if (employeeNo == null) employeeNo = "";
		if (name == null) name = "";
		if (birthday == null) birthday = "";
		if(rows != 0)employeeService.setRows(rows);
		List<Employee> employeeList = employeeService.queryEmployee(employeeNo, positionObj, name, birthday, page);
	    /*计算总的页数和总的记录数*/
	    employeeService.queryTotalPageAndRecordNumber(employeeNo, positionObj, name, birthday);
	    /*获取到总的页码数目*/
	    int totalPage = employeeService.getTotalPage();
	    /*当前查询条件下总记录数*/
        try { 
        	int count = departmentService.deleteDepartments(departmentNos);
        	success = true;
        	message = count + "条记录删除成功";
        	writeJsonResponse(response, success, message);
        } catch (Exception e) { 
            //e.printStackTrace();
            message = "有记录存在外键约束,删除失败";
            writeJsonResponse(response, success, message);
        }
	}

	/*按照查询条件导出部门信息到Excel*/
	@RequestMapping(value = { "/OutToExcel" }, method = {RequestMethod.GET,RequestMethod.POST})
	public void OutToExcel( Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
        List<Department> departmentList = departmentService.queryDepartment();
        ExportExcelUtil ex = new ExportExcelUtil();
        String title = "Department信息记录"; 
        String[] headers = { "部门编号","部门名称"};
        List<String[]> dataset = new ArrayList<String[]>(); 
        for(int i=0;i<departmentList.size();i++) {
        	Department department = departmentList.get(i); 
        	dataset.add(new String[]{department.getDepartmentNo(),department.getDepartmentName()});
        }
        /*
        OutputStream out = null;
		try {
			out = new FileOutputStream("C://output.xls");
			ex.exportExcel(title,headers, dataset, out);
		    out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		*/
		OutputStream out = null;//创建一个输出流对象 
		try { 
			out = response.getOutputStream();//
			response.setHeader("Content-disposition","attachment; filename="+"Department.xls");//filename是下载的xls的名,建议最好用英文 
			response.setContentType("application/msexcel;charset=UTF-8");//设置类型 
			response.setHeader("Pragma","No-cache");//设置头 
			response.setHeader("Cache-Control","no-cache");//设置头 
			response.setDateHeader("Expires", 0);//设置日期头  
			String rootPath = request.getSession().getServletContext().getRealPath("/");
			ex.exportExcel(rootPath,title,headers, dataset, out);
			out.flush();
		} catch (IOException e) { 
			e.printStackTrace(); 
		}finally{
			try{
				if(out!=null){ 
		if (br.hasErrors()) {
			message = "输入信息不符合要求!";
			writeJsonResponse(response, success, message);
			return ;
		}
        positionService.addPosition(position);
        message = "职位添加成功!";
        success = true;
        writeJsonResponse(response, success, message);
	}
	/*ajax方式按照查询条件分页查询职位信息*/
	@RequestMapping(value = { "/list" }, method = {RequestMethod.GET,RequestMethod.POST})
	public void list(@ModelAttribute("departmentObj") Department departmentObj,String positionName,Integer page,Integer rows, Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
		if (page==null || page == 0) page = 1;
		if (positionName == null) positionName = "";
		if(rows != 0)positionService.setRows(rows);
		List<Position> positionList = positionService.queryPosition(departmentObj, positionName, page);
	    /*计算总的页数和总的记录数*/
	    positionService.queryTotalPageAndRecordNumber(departmentObj, positionName);
	    /*获取到总的页码数目*/
	    int totalPage = positionService.getTotalPage();
	    /*当前查询条件下总记录数*/
	    int recordNumber = positionService.getRecordNumber();
        response.setContentType("text/json;charset=UTF-8");
		PrintWriter out = response.getWriter();
		//将要被返回到客户端的对象
		JSONObject jsonObj=new JSONObject();
		jsonObj.accumulate("total", recordNumber);
		JSONArray jsonArray = new JSONArray();
		for(Position position:positionList) {
			JSONObject jsonPosition = position.getJsonObject();
			jsonArray.put(jsonPosition);
		}
		jsonObj.accumulate("rows", jsonArray);
		out.println(jsonObj.toString().replace("[[","[").replace("]]","]"));
		out.flush();
		out.close();
	}

	/*ajax方式按照查询条件分页查询职位信息*/
	@RequestMapping(value = { "/listAll" }, method = {RequestMethod.GET,RequestMethod.POST})
	public void listAll(HttpServletResponse response) throws Exception {
		List<Position> positionList = positionService.queryAllPosition();
        response.setContentType("text/json;charset=UTF-8"); 
		PrintWriter out = response.getWriter();
		JSONArray jsonArray = new JSONArray();
		for(Position position:positionList) {
			JSONObject jsonPosition = new JSONObject();
			jsonPosition.accumulate("positionId", position.getPositionId());
			jsonPosition.accumulate("positionName", position.getPositionName());
			jsonArray.put(jsonPosition);
			try{
				if(out!=null){ 
					out.close(); 
				}
			}catch(IOException e){ 
				e.printStackTrace(); 
			} 
		}
    }
}

//Department管理控制层
@Controller
@RequestMapping("/Department")
public class DepartmentController extends BaseController {

    /*业务层对象*/
    @Resource DepartmentService departmentService;
	}

	/*按照查询条件导出职位信息到Excel*/
	@RequestMapping(value = { "/OutToExcel" }, method = {RequestMethod.GET,RequestMethod.POST})
	public void OutToExcel(@ModelAttribute("departmentObj") Department departmentObj,String positionName, Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
        if(positionName == null) positionName = "";
        List<Position> positionList = positionService.queryPosition(departmentObj,positionName);
        ExportExcelUtil ex = new ExportExcelUtil();
        String title = "Position信息记录"; 
        String[] headers = { "职位id","所属部门","职位名称","基本工资","销售提成"};
        List<String[]> dataset = new ArrayList<String[]>(); 
        for(int i=0;i<positionList.size();i++) {
        	Position position = positionList.get(i); 
        	dataset.add(new String[]{position.getPositionId() + "",position.getDepartmentObj().getDepartmentName(),position.getPositionName(),position.getBaseSalary() + "",position.getSellPercent()});
        }
        /*
        OutputStream out = null;
		try {
			out = new FileOutputStream("C://output.xls");
			ex.exportExcel(title,headers, dataset, out);
		    out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		*/
		OutputStream out = null;//创建一个输出流对象 
		try { 
			out = response.getOutputStream();//
			response.setHeader("Content-disposition","attachment; filename="+"Position.xls");//filename是下载的xls的名,建议最好用英文 
			response.setContentType("application/msexcel;charset=UTF-8");//设置类型 
			response.setHeader("Pragma","No-cache");//设置头 
			response.setHeader("Cache-Control","no-cache");//设置头 
			response.setDateHeader("Expires", 0);//设置日期头  
			String rootPath = request.getSession().getServletContext().getRealPath("/");
			ex.exportExcel(rootPath,title,headers, dataset, out);
			out.flush();
		} catch (IOException e) { 
			e.printStackTrace(); 
		}finally{
			try{
				if(out!=null){ 
					out.close(); 
				}
			}catch(IOException e){ 
		binder.registerCustomEditor(Date.class, new CustomDateEditor(
				new SimpleDateFormat("yyyy-MM-dd"), false));
	 
		binder.registerCustomEditor(Integer.class, new PropertyEditorSupport() {
			@Override
			public String getAsText() { 
				return (getValue() == null) ? "" : getValue().toString();
			} 
			@Override
			public void setAsText(String text) {
				Integer value = null;
				if (null != text && !text.equals("")) {  
						try {
							value = Integer.valueOf(text);
						} catch(Exception ex)  { 
							throw new UserException("数据格式输入不正确!"); 
						}  
				}
				setValue(value);
			} 
		});
	  
		//binder.registerCustomEditor(Integer.class, null,new CustomNumberEditor(Integer.class, null, true));
		
		binder.registerCustomEditor(Float.class, new PropertyEditorSupport() {
			@Override
			public String getAsText() { 
				return (getValue() == null)? "" : getValue().toString();
			} 
			@Override
			public void setAsText(String text)  {
				Float value = null;
				if (null != text && !text.equals("")) {
					try {
						value = Float.valueOf(text);
					} catch (Exception e) { 
						throw new UserException("数据格式输入不正确!"); 
					}
				}
				setValue(value);
			}
		});
	}
 
	/** 
	 * 处理图片文件上传,返回保存的文件名路径
	 * fileKeyName: 图片上传表单key
	 * @throws IOException 
	    request.setAttribute("departmentList",  departmentList);
	    request.setAttribute("totalPage", totalPage);
	    request.setAttribute("recordNumber", recordNumber);
	    request.setAttribute("currentPage", currentPage);
		return "Department/department_frontquery_result"; 
	}

     /*前台查询Department信息*/
	@RequestMapping(value="/{departmentNo}/frontshow",method=RequestMethod.GET)
	public String frontshow(@PathVariable String departmentNo,Model model,HttpServletRequest request) throws Exception {
		/*根据主键departmentNo获取Department对象*/
        Department department = departmentService.getDepartment(departmentNo);

        request.setAttribute("department",  department);
        return "Department/department_frontshow";
	}

	/*ajax方式显示部门修改jsp视图页*/
	@RequestMapping(value="/{departmentNo}/update",method=RequestMethod.GET)
	public void update(@PathVariable String departmentNo,Model model,HttpServletRequest request,HttpServletResponse response) throws Exception {
        /*根据主键departmentNo获取Department对象*/
        Department department = departmentService.getDepartment(departmentNo);

        response.setContentType("text/json;charset=UTF-8");
        PrintWriter out = response.getWriter();
		//将要被返回到客户端的对象 
		JSONObject jsonDepartment = department.getJsonObject();
		out.println(jsonDepartment.toString());
		out.flush();
		out.close();
	}

	/*ajax方式更新部门信息*/
	@RequestMapping(value = "/{departmentNo}/update", method = RequestMethod.POST)
	public void update(@Validated Department department, BindingResult br,
			Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
		String message = "";
    	boolean success = false;
		if (br.hasErrors()) { 
			message = "输入的信息有错误!";
			writeJsonResponse(response, success, message);
			return;
		}
		try {
			departmentService.updateDepartment(department);
			message = "部门更新成功!";
			success = true;
			writeJsonResponse(response, success, message);
		} catch (Exception e) {
			e.printStackTrace();
			message = "部门更新失败!";
	@RequestMapping(value="/{departmentNo}/update",method=RequestMethod.GET)
	public void update(@PathVariable String departmentNo,Model model,HttpServletRequest request,HttpServletResponse response) throws Exception {
        /*根据主键departmentNo获取Department对象*/
        Department department = departmentService.getDepartment(departmentNo);

        response.setContentType("text/json;charset=UTF-8");
        PrintWriter out = response.getWriter();
		//将要被返回到客户端的对象 
		JSONObject jsonDepartment = department.getJsonObject();
		out.println(jsonDepartment.toString());
		out.flush();
		out.close();
	}

	/*ajax方式更新部门信息*/
	@RequestMapping(value = "/{departmentNo}/update", method = RequestMethod.POST)
	public void update(@Validated Department department, BindingResult br,
			Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
		String message = "";
    	boolean success = false;
		if (br.hasErrors()) { 
			message = "输入的信息有错误!";
			writeJsonResponse(response, success, message);
			return;
		}
		try {
			departmentService.updateDepartment(department);
			message = "部门更新成功!";
			success = true;
			writeJsonResponse(response, success, message);
		} catch (Exception e) {
			e.printStackTrace();
			message = "部门更新失败!";
			writeJsonResponse(response, success, message); 
		}
	}
    /*删除部门信息*/
	@RequestMapping(value="/{departmentNo}/delete",method=RequestMethod.GET)
	public String delete(@PathVariable String departmentNo,HttpServletRequest request) throws UnsupportedEncodingException {
		  try {
			  departmentService.deleteDepartment(departmentNo);
	            request.setAttribute("message", "部门删除成功!");
	            return "message";

public class BaseController {
	
	
	
	@InitBinder
	// 必须有一个参数WebDataBinder
	public void initBinder(WebDataBinder binder) {
		//System.out.println(binder.getFieldDefaultPrefix());
		binder.registerCustomEditor(Date.class, new CustomDateEditor(
				new SimpleDateFormat("yyyy-MM-dd"), false));
	 
		binder.registerCustomEditor(Integer.class, new PropertyEditorSupport() {
			@Override
			public String getAsText() { 
				return (getValue() == null) ? "" : getValue().toString();
			} 
			@Override
			public void setAsText(String text) {
				Integer value = null;
				if (null != text && !text.equals("")) {  
						try {
							value = Integer.valueOf(text);
						} catch(Exception ex)  { 
							throw new UserException("数据格式输入不正确!"); 
						}  
				}
				setValue(value);
			} 
		});
	  
		//binder.registerCustomEditor(Integer.class, null,new CustomNumberEditor(Integer.class, null, true));
		
		binder.registerCustomEditor(Float.class, new PropertyEditorSupport() {
			@Override
			public String getAsText() { 
				return (getValue() == null)? "" : getValue().toString();
			} 
			@Override
			public void setAsText(String text)  {
				Float value = null;
				if (null != text && !text.equals("")) {
					try {
						value = Float.valueOf(text);
					} catch (Exception e) { 
						throw new UserException("数据格式输入不正确!"); 

//Employee管理控制层
@Controller
@RequestMapping("/Employee")
public class EmployeeController extends BaseController {

    /*业务层对象*/
    @Resource EmployeeService employeeService;

    @Resource PositionService positionService;
	@InitBinder("positionObj")
	public void initBinderpositionObj(WebDataBinder binder) {
		binder.setFieldDefaultPrefix("positionObj.");
	}
	@InitBinder("employee")
	public void initBinderEmployee(WebDataBinder binder) {
		binder.setFieldDefaultPrefix("employee.");
	}
	/*跳转到添加Employee视图*/
	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public String add(Model model,HttpServletRequest request) throws Exception {
		model.addAttribute(new Employee());
        PrintWriter out = response.getWriter();
		//将要被返回到客户端的对象 
		JSONObject jsonPosition = position.getJsonObject();
		out.println(jsonPosition.toString());
		out.flush();
		out.close();
	}

	/*ajax方式更新职位信息*/
	@RequestMapping(value = "/{positionId}/update", method = RequestMethod.POST)
	public void update(@Validated Position position, BindingResult br,
			Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
		String message = "";
    	boolean success = false;
		if (br.hasErrors()) { 
			message = "输入的信息有错误!";
			writeJsonResponse(response, success, message);
			return;
		}
		try {
			positionService.updatePosition(position);
			message = "职位更新成功!";
			success = true;
			writeJsonResponse(response, success, message);
		} catch (Exception e) {
			e.printStackTrace();
			message = "职位更新失败!";
			writeJsonResponse(response, success, message); 
		}
	}
    /*删除职位信息*/
	@RequestMapping(value="/{positionId}/delete",method=RequestMethod.GET)
	public String delete(@PathVariable Integer positionId,HttpServletRequest request) throws UnsupportedEncodingException {
		  try {
			  positionService.deletePosition(positionId);
	            request.setAttribute("message", "职位删除成功!");
	            return "message";
	        } catch (Exception e) { 
	            e.printStackTrace();
	            request.setAttribute("error", "职位删除失败!");

请添加图片描述

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值