Skip to content

Instantly share code, notes, and snippets.

@circlee
Created January 8, 2019 16:56
Show Gist options
  • Save circlee/c36963e8af7d8c304299c04d7b995ca1 to your computer and use it in GitHub Desktop.
Save circlee/c36963e8af7d8c304299c04d7b995ca1 to your computer and use it in GitHub Desktop.
@Override
public Object intercept(Invocation invocation) throws Throwable {
Object[] args = invocation.getArgs();
MappedStatement ms = (MappedStatement)args[0];
Object param = (Object)args[1];
BoundSql boundSql = ms.getBoundSql(param);
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
TypeHandlerRegistry typeHandlerRegistry = ms.getConfiguration().getTypeHandlerRegistry();
for (ParameterMapping parameterMapping : parameterMappings) {
if (parameterMapping.getMode() != ParameterMode.OUT) {
Object value;
String propertyName = parameterMapping.getProperty();
if (boundSql.hasAdditionalParameter(propertyName)) {
value = boundSql.getAdditionalParameter(propertyName);
} else if (parameterObject == null) {
value = null;
} else if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) {
value = parameterObject;
} else {
MetaObject metaObject = configuration.newMetaObject(parameterObject);
value = metaObject.getValue(propertyName);
}
log.debug("value : {}" , value);
}
}
return invocation.proceed();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment