项目用的是Hibernate+Jquery-easyui,介绍的是多表关联的增删改操作。

很简单:只需要在多表关联的表,如员工表中关联了部门表插入数据时不能直接通过网页提交表单插入关联的部门,需要在Controller处的new一个对象,通过对象添加数据。

增加

//Servlet下的代码Deptdept=deptService.findByIdIfo(Integer.parseInt(req.getParameter("deptId")));employee.setDept(dept);//最后把employee添加saveEmpInfo相应方法写在service层和dao层在此忽略empService.saveEmpInfo(employee);


删除

直接删除该行数据如empId(通过前台传回后台的f_id),不需要做处理


修改

//部门Deptdept=newDept();booleanflag1=true;//查找全部部门信息循环比较(需要用到预留列)List<Dept>list1=deptService.findAllInfo();for(Deptd:list1){if(d.getDeptName().equals(req.getParameter("deptId"))){flag1=false;}}if(!flag1){employee.setDeptTemp(req.getParameter("deptId"));}else{dept=deptService.findByIdIfo(Integer.parseInt(req.getParameter("deptId")));employee.setDept(dept);}empService.updateEmpInfo(employee);