基于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的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方式提交添加职位信息*/
@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();
//将要被返回到客户端的对象
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();
}
} 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 {
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);
@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");
PrintWriter out = response.getWriter();
//将要被返回到客户端的对象
JSONObject json=new JSONObject();
json.accumulate("success", success);
json.accumulate("msg", msg);
out.println(json.toString());
out.flush();
out.close();
}
@RequestMapping("/logout")
public String logout(Model model,HttpSession session) {
model.asMap().remove("username");
session.invalidate();
return "redirect:/login";
}
@RequestMapping(value="/changePassword",method=RequestMethod.POST)
public String ChangePassword(String oldPassword,String newPassword,String newPassword2,HttpServletRequest request,HttpSession session) throws Exception {
if(oldPassword.equals("")) throw new UserException("请输入旧密码!");
if(newPassword.equals("")) throw new UserException("请输入新密码!");
if(!newPassword.equals(newPassword2)) throw new UserException("两次新密码输入不一致");
String username = (String)session.getAttribute("username");
if(username == null) throw new UserException("session会话超时,请重新登录系统!");
public void listAll(HttpServletResponse response) throws Exception {
List<Employee> employeeList = employeeService.queryAllEmployee();
response.setContentType("text/json;charset=UTF-8");
PrintWriter out = response.getWriter();
JSONArray jsonArray = new JSONArray();
for(Employee employee:employeeList) {
JSONObject jsonEmployee = new JSONObject();
jsonEmployee.accumulate("employeeNo", employee.getEmployeeNo());
jsonEmployee.accumulate("name", employee.getName());
jsonArray.put(jsonEmployee);
}
out.println(jsonArray.toString());
out.flush();
out.close();
}
/*前台按照查询条件分页查询员工信息*/
@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("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 = "部门更新失败!";
writeJsonResponse(response, success, message);
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();
out.close();
}
/*前台按照查询条件分页查询职位信息*/
@RequestMapping(value = { "/frontlist" }, method = {RequestMethod.GET,RequestMethod.POST})
public String frontlist(@ModelAttribute("departmentObj") Department departmentObj,String positionName,Integer currentPage, Model model, HttpServletRequest request) throws Exception {
if (currentPage==null || currentPage == 0) currentPage = 1;
if (positionName == null) positionName = "";
List<Position> positionList = positionService.queryPosition(departmentObj, positionName, currentPage);
/*计算总的页数和总的记录数*/
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();
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();
}
}
}
}
List<Employee> employeeList = employeeService.queryEmployee(employeeNo,positionObj,name,birthday);
ExportExcelUtil ex = new ExportExcelUtil();
String title = "Employee信息记录";
String[] headers = { "员工编号","职位","姓名","性别","员工照片","出生日期","学历"};
List<String[]> dataset = new ArrayList<String[]>();
for(int i=0;i<employeeList.size();i++) {
Employee employee = employeeList.get(i);
dataset.add(new String[]{employee.getEmployeeNo(),employee.getPositionObj().getPositionName(),employee.getName(),employee.getSex(),employee.getEmployeePhoto(),employee.getBirthday(),employee.getSchoolRecord()});
}
/*
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="+"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();
}
}
}
}
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);
} 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";
//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.");
}
//Position管理控制层
@Controller
@RequestMapping("/Position")
public class PositionController extends BaseController {
/*业务层对象*/
@Resource PositionService positionService;
@Resource DepartmentService departmentService;
@InitBinder("departmentObj")
/*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 = "";
boolean success = false;
try {
int count = positionService.deletePositions(positionIds);
success = true;
@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");
PrintWriter out = response.getWriter();
//将要被返回到客户端的对象
JSONObject json=new JSONObject();
json.accumulate("success", success);
json.accumulate("msg", msg);
out.println(json.toString());
out.flush();
out.close();
}
@RequestMapping("/logout")
public String logout(Model model,HttpSession session) {
model.asMap().remove("username");
session.invalidate();
String message = "";
boolean success = false;
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) {
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();
//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());
/*查询所有的Position信息*/
List<Position> positionList = positionService.queryAllPosition();
request.setAttribute("positionList", positionList);
return "Employee_add";
}
/*客户端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 {
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 = "";
boolean success = false;
try {
int count = positionService.deletePositions(positionIds);
success = true;
message = count + "条记录删除成功";
writeJsonResponse(response, success, message);
} catch (Exception e) {
//e.printStackTrace();






更多推荐



所有评论(0)