SSH中更新方法为什么不直接更新?
为什么不是:
public String edit() throws Exception {
(已经实现了ModelDriven接口)
departmentService.update(department);
return "toList";
}
而是:
/** 修改 */
public String edit() throws Exception {
// 1,从数据库取出原对象
Department department = departmentService.getById(model.getId());
// 2,设置要修改的属性
department.setName(model.getName());
department.setDescription(model.getDescription());
// 3,更新到数据库中
departmentService.update(department);
return "toList";
}
你那么写是报错还是什么?_?
直接更新是操作整条数据,部分更新只是操作部分字段。 添加,修改对服务器压力是很大的。这样能减轻服务器压力