加载父对象后,您说
现在,我只想允许用户更新父项的field2属性
根据用例,您可以使用UpdateableParent对象
public class UpdateableParent { private String field2; // getter's and setter's}现在我们的父仓库
@Repositorypublic class ParentRepositoryImpl implements ParentRepository { @Autowired private SessionFactory sessionFactory; public void updateSpecificUseCase(UpdateableParent updateableParentObject) { Parent parent = sessionFactory.getCurrentSession().load(Parent.class, updateableParentObject.getId()); try { // jakarta commons takes care of copying Updateable Parent object to Parent object BeanUtils.copyProperties(parent, updateableParentObject); } catch (Exception e) { throw new IllegalStateException("Error occured when updating a Parent object", e); } }}优点
- 这很安全:您只需更新自己真正想要的
- 您不必担心MVC框架(某些MVC框架允许您设置allowedFields属性)。如果您忘记了一些允许的字段,会发生什么?
尽管这不是与技术相关的问题,但是Seam框架仅允许您更新所需的内容。因此,您不必担心要使用哪种模式。
问候,



