*/
@Override
public boolean onSave(E entity, BasicHibernateDao<E, ID> persistentContext,Serializable id) {
Class<?> entityClass = ReflectionUtils.getTargetClass(entity);
SecurityCode securityCode = ReflectionUtils.getAnnotation(entityClass,SecurityCode.class);
if (securityCode != null) {
if (id == null || id.toString().equals("")) {
String code = generateSecurityCode(entity,securityCode);
ReflectionUtils.invokeSetterMethod(entity, securityCode.value(), code);
} else {
E e = persistentContext.get((ID) id);
String originalCode = ReflectionUtils.invokeGetterMethod(e, securityCode.value());
String currentCode = generateSecurityCode(e, securityCode);
if (!StringUtils.equals(originalCode, currentCode)) {
throw new SecurityCodeNotEqualException("安全码不正确,原始码为:" + originalCode + "当前对象的安全码为:" + currentCode);
}
ReflectionUtils.invokeSetterMethod(entity, securityCode.value(), currentCode);
}
}
return Boolean.TRUE;