Ejemplo n.º 1
0
 public String insert() {
   /** 如何获取页面中的数据 * 如果页面中的数据来源于一张表,直接用模型驱动获取就可以了 * 如果页面中的数据来源于多张表,则可以采用模型驱动结合属性驱动的方式 */
   /** 1、创建一个employee对象 2、把模型驱动的值赋值给employee对象 3、根据 部门id提取出该部门 4、建立employee对象和部门之间的关系 5、执行save操作 */
   Employee employee = new Employee();
   // 一般属性的赋值
   BeanUtils.copyProperties(this.getModel(), employee);
   // 建立员工与部门之间的关系
   Department department = this.departmentService.getDepartment(Integer.parseInt(did));
   employee.setDepartment(department);
   // 创建时间
   employee.setCreateTime(new Date());
   this.employeeService.saveEmployee(employee);
   return action2action;
 }
Ejemplo n.º 2
0
 public String update() {
   /**
    * 1、利用模型驱动获取员工的一般数据 2、利用属性驱动获取最新的did和eid 3、根据员工的id提取出employee对象 4、把模型驱动的值复制到employee对象中
    * 5、重新建立employee对象部门之间的关系
    */
   // 一般属性的赋值
   Employee employee = this.employeeService.getEmployee(this.getModel().getId());
   Date createTime = employee.getCreateTime();
   BeanUtils.copyProperties(this.getModel(), employee);
   // 重新建立员工与部门之间的关系
   Department department =
       this.departmentService.getDepartment(this.getModel().getDepartment().getId());
   employee.setCreateTime(createTime);
   employee.setDepartment(department);
   this.employeeService.updateEmployee(employee);
   return action2action;
 }