基于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,所属部门,职位名称,基本工资,销售提成

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

	/*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();
	}

	/*ajax方式更新员工信息*/
	@RequestMapping(value = "/{employeeNo}/update", method = RequestMethod.POST)
	public void update(@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;
		}
		String employeePhotoFileName = this.handlePhotoUpload(request, "employeePhotoFile");
		if(!employeePhotoFileName.equals("upload/NoImage.jpg"))employee.setEmployeePhoto(employeePhotoFileName); 

		try {
			employeeService.updateEmployee(employee);
			message = "员工更新成功!";
			success = true;
			writeJsonResponse(response, success, message);
		} catch (Exception e) {
			e.printStackTrace();
			message = "员工更新失败!";
			writeJsonResponse(response, success, message); 
		}
	@InitBinder("departmentObj")
	public void initBinderdepartmentObj(WebDataBinder binder) {
		binder.setFieldDefaultPrefix("departmentObj.");
	}
	@InitBinder("position")
	public void initBinderPosition(WebDataBinder binder) {
		binder.setFieldDefaultPrefix("position.");
	}
	/*跳转到添加Position视图*/
	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public String add(Model model,HttpServletRequest request) throws Exception {
		model.addAttribute(new Position());
		/*查询所有的Department信息*/
		List<Department> departmentList = departmentService.queryAllDepartment();
		request.setAttribute("departmentList", departmentList);
		return "Position_add";
	}

	/*客户端ajax方式提交添加职位信息*/
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public void add(@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 ;
		}
        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();
	    /*计算总的页数和总的记录数*/
	    positionService.queryTotalPageAndRecordNumber(departmentObj, positionName);
	    /*获取到总的页码数目*/
	    int totalPage = positionService.getTotalPage();
	    /*当前查询条件下总记录数*/
	    int recordNumber = positionService.getRecordNumber();
	    request.setAttribute("positionList",  positionList);
	    request.setAttribute("totalPage", totalPage);
	    request.setAttribute("recordNumber", recordNumber);
	    request.setAttribute("currentPage", currentPage);
	    request.setAttribute("departmentObj", departmentObj);
	    request.setAttribute("positionName", positionName);
	    List<Department> departmentList = departmentService.queryAllDepartment();
	    request.setAttribute("departmentList", departmentList);
		return "Position/position_frontquery_result"; 
	}

     /*前台查询Position信息*/
	@RequestMapping(value="/{positionId}/frontshow",method=RequestMethod.GET)
	public String frontshow(@PathVariable Integer positionId,Model model,HttpServletRequest request) throws Exception {
		/*根据主键positionId获取Position对象*/
        Position position = positionService.getPosition(positionId);

        List<Department> departmentList = departmentService.queryAllDepartment();
        request.setAttribute("departmentList", departmentList);
        request.setAttribute("position",  position);
        return "Position/position_frontshow";
	}

	/*ajax方式显示职位修改jsp视图页*/
	@RequestMapping(value="/{positionId}/update",method=RequestMethod.GET)
	public void update(@PathVariable Integer positionId,Model model,HttpServletRequest request,HttpServletResponse response) throws Exception {
        /*根据主键positionId获取Position对象*/
        Position position = positionService.getPosition(positionId);

        response.setContentType("text/json;charset=UTF-8");
        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 {

     /*前台查询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 = "部门更新失败!";
		//将要被返回到客户端的对象 
		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", "职位删除失败!");
				return "error";

	        }

	}

	/*ajax方式删除多条职位记录*/
	@RequestMapping(value="/deletes",method=RequestMethod.POST)
	public void delete(String positionIds,HttpServletRequest request,HttpServletResponse response) throws IOException, JSONException {
		String message = "";
		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();
	}

	/*ajax方式更新员工信息*/
	@RequestMapping(value = "/{employeeNo}/update", method = RequestMethod.POST)
	public void update(@Validated Employee employee, BindingResult br,
			Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
		String message = "";
    	boolean success = false;
	    request.setAttribute("departmentList", departmentList);
		return "Position/position_frontquery_result"; 
	}

     /*前台查询Position信息*/
	@RequestMapping(value="/{positionId}/frontshow",method=RequestMethod.GET)
	public String frontshow(@PathVariable Integer positionId,Model model,HttpServletRequest request) throws Exception {
		/*根据主键positionId获取Position对象*/
        Position position = positionService.getPosition(positionId);

        List<Department> departmentList = departmentService.queryAllDepartment();
        request.setAttribute("departmentList", departmentList);
        request.setAttribute("position",  position);
        return "Position/position_frontshow";
	}

	/*ajax方式显示职位修改jsp视图页*/
	@RequestMapping(value="/{positionId}/update",method=RequestMethod.GET)
	public void update(@PathVariable Integer positionId,Model model,HttpServletRequest request,HttpServletResponse response) throws Exception {
        /*根据主键positionId获取Position对象*/
        Position position = positionService.getPosition(positionId);

        response.setContentType("text/json;charset=UTF-8");
        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);
		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();
	    /*当前查询条件下总记录数*/
	    int recordNumber = employeeService.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(Employee employee:employeeList) {
			JSONObject jsonEmployee = employee.getJsonObject();
			jsonArray.put(jsonEmployee);
		}
			Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
		String message = "";
		boolean success = false;
		if (br.hasErrors()) {
			message = "输入信息不符合要求!";
			writeJsonResponse(response, success, message);
			return ;
		}
		if(departmentService.getDepartment(department.getDepartmentNo()) != null) {
			message = "部门编号已经存在!";
			writeJsonResponse(response, success, message);
			return ;
		}
        departmentService.addDepartment(department);
        message = "部门添加成功!";
        success = true;
        writeJsonResponse(response, success, message);
	}
	/*ajax方式按照查询条件分页查询部门信息*/
	@RequestMapping(value = { "/list" }, method = {RequestMethod.GET,RequestMethod.POST})
	public void list(Integer page,Integer rows, Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
		if (page==null || page == 0) page = 1;
		if(rows != 0)departmentService.setRows(rows);
		List<Department> departmentList = departmentService.queryDepartment(page);
	    /*计算总的页数和总的记录数*/
	    departmentService.queryTotalPageAndRecordNumber();
	    /*获取到总的页码数目*/
	    int totalPage = departmentService.getTotalPage();
	    /*当前查询条件下总记录数*/
	    int recordNumber = departmentService.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(Department department:departmentList) {
			JSONObject jsonDepartment = department.getJsonObject();
			jsonArray.put(jsonDepartment);
		}
		jsonObj.accumulate("rows", jsonArray);
		out.println(jsonObj.toString().replace("[[","[").replace("]]","]"));
		out.flush();
		out.close();
	}

	/*ajax方式按照查询条件分页查询部门信息*/
	@RequestMapping(value = { "/listAll" }, method = {RequestMethod.GET,RequestMethod.POST})

	/*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 = "部门更新失败!";
			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";
	        } catch (Exception e) { 
	            e.printStackTrace();

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

	/*ajax方式更新员工信息*/
	@RequestMapping(value = "/{employeeNo}/update", method = RequestMethod.POST)
	public void update(@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;
		}
		String employeePhotoFileName = this.handlePhotoUpload(request, "employeePhotoFile");
		if(!employeePhotoFileName.equals("upload/NoImage.jpg"))employee.setEmployeePhoto(employeePhotoFileName); 

		try {
			employeeService.updateEmployee(employee);
			message = "员工更新成功!";
			success = true;
			writeJsonResponse(response, success, message);
		} catch (Exception e) {
			e.printStackTrace();
			message = "员工更新失败!";
			writeJsonResponse(response, success, message); 
		}
	}
    /*删除员工信息*/
	@RequestMapping(value="/{employeeNo}/delete",method=RequestMethod.GET)
	public String delete(@PathVariable String employeeNo,HttpServletRequest request) throws UnsupportedEncodingException {
		  try {
			  employeeService.deleteEmployee(employeeNo);
	            request.setAttribute("message", "员工删除成功!");
	            return "message";
	        } catch (Exception e) { 
	            e.printStackTrace();
	            request.setAttribute("error", "员工删除失败!");
				return "error";

	        }

	}

	/*ajax方式删除多条员工记录*/
	
	
	@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("数据格式输入不正确!"); 
					}
				}
				setValue(value);
			}
		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);
		}
		out.println(jsonArray.toString());
		out.flush();
     /*前台查询Position信息*/
	@RequestMapping(value="/{positionId}/frontshow",method=RequestMethod.GET)
	public String frontshow(@PathVariable Integer positionId,Model model,HttpServletRequest request) throws Exception {
		/*根据主键positionId获取Position对象*/
        Position position = positionService.getPosition(positionId);

        List<Department> departmentList = departmentService.queryAllDepartment();
        request.setAttribute("departmentList", departmentList);
        request.setAttribute("position",  position);
        return "Position/position_frontshow";
	}

	/*ajax方式显示职位修改jsp视图页*/
	@RequestMapping(value="/{positionId}/update",method=RequestMethod.GET)
	public void update(@PathVariable Integer positionId,Model model,HttpServletRequest request,HttpServletResponse response) throws Exception {
        /*根据主键positionId获取Position对象*/
        Position position = positionService.getPosition(positionId);

        response.setContentType("text/json;charset=UTF-8");
        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;

  

 
@Controller
@SessionAttributes("username")
public class SystemController { 
	
	@Resource AdminService adminService;  
	
	@RequestMapping(value="/login",method=RequestMethod.GET)
	public String login(Model model) {
		model.addAttribute(new Admin());
		return "login";
	}

	@RequestMapping(value="/login",method=RequestMethod.POST)
	public void login(@Validated Admin admin,BindingResult br,Model model,HttpServletRequest request,HttpServletResponse response,HttpSession session) throws Exception { 
		boolean success = true;
		String msg = ""; 
		if(br.hasErrors()) {
			msg = br.getAllErrors().toString();
			success = false;  
		} 
		if (!adminService.checkLogin(admin)) { 
			msg = adminService.getErrMessage();
			success = false; 
		} 
		if(success) {
			session.setAttribute("username", admin.getUsername()); 
		}  
        response.setContentType("text/json;charset=UTF-8");  

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

    /*业务层对象*/
    @Resource PositionService positionService;

    @Resource DepartmentService departmentService;
	@InitBinder("departmentObj")
	public void initBinderdepartmentObj(WebDataBinder binder) {
		binder.setFieldDefaultPrefix("departmentObj.");
	}
	@InitBinder("position")
	public void initBinderPosition(WebDataBinder binder) {
		binder.setFieldDefaultPrefix("position.");
	}
	/*跳转到添加Position视图*/
	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public String add(Model model,HttpServletRequest request) throws Exception {
		model.addAttribute(new Position());
		/*查询所有的Department信息*/
		List<Department> departmentList = departmentService.queryAllDepartment();
		request.setAttribute("departmentList", departmentList);
		return "Position_add";
	}

	/*客户端ajax方式提交添加职位信息*/
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public void add(@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 ;
		}
        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 = "";

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

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

	@InitBinder("department")
	public void initBinderDepartment(WebDataBinder binder) {
		binder.setFieldDefaultPrefix("department.");
	}
	/*跳转到添加Department视图*/
	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public String add(Model model,HttpServletRequest request) throws Exception {
		model.addAttribute(new Department());
		return "Department_add";
	}

	/*客户端ajax方式提交添加部门信息*/
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public void add(@Validated Department department, BindingResult br,
			Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
		String message = "";
		boolean success = false;
		if (br.hasErrors()) {

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值