假设这个类图:如何在不更改代码的情况下将限制应用到Spring/hibernate企业应用程序中的所有业务点?
我有一个名为Organization
许多对象有关联的那类。除了StoreHouse
和Personnel
之外,还有许多对象,但是为了具有简单的类图,我没有将这些类放入图中(假定超过1000个类依赖于Organization
类)。
现在,我想添加enabled
字段到Organization
类。这很简单,没有任何问题。但在此之后,我想阻止所有业务点和服务使用disabled
组织。
例如假定此以下服务:
@Service
public class PersonnelService {
@Autowired
private PersonnelRepository repository;
public long save(Personnel entity) {
return repository.save(entity);
}
}
如果我有以上应用程序中的代码,enabled
字段添加到Organization
后,我应该上述方法改变为这样:
@Service
public class PersonnelService {
@Autowired
private PersonnelRepository repository;
public long save(Personnel entity) {
if(!entity.getOrganization().getEnabled()) {
throw Exception();
}
return repository.save(entity);
}
}
而因为这个动作非常耗时,要换1000多班。 我想知道是否有办法在不更改业务点的情况下执行此操作(例如使用Aspect或类似方法),并检测修改是在对象上进行的,并且其类型为Organization
的字段检查enabled
值?
定义'@ Where'上过滤的'enabled'属性的组织。这样残疾人组织就看不见了。 –