参考:
https://www.jianshu.com/p/0a72bb1f6a21
https://www.extlight.com/2018/06/13/Mybatis-%E6%8F%92%E4%BB%B6%E5%AE%9E%E7%8E%B0%E5%8A%A8%E6%80%81%E8%AE%BE%E7%BD%AE%E5%8F%82%E6%95%B0/
@Component
@Slf4j
@Intercepts({@Signature(type = Executor.class, method = 'update', args = {MapperdStatement.class, Object.class} ) } )
public class CreateUserInterceptor implements Interceptor {
public Object intercept(Invovation invocation) throws Throwable {
MapperdStatement ms = Invocation.getArgs()[0];
Object parameter = invocation.getArgs()[1];
SqlCommandType sqlCommandType = ms.getSqlCommandType();
Field field = null;
if(SqlCommandType.INSERT.equals(sqlCommandType)){
field = this.getField(parameter.getClass(),"CREATEUSER");
}esle if(SqlCommandType.UPDATE.equals(sqlCommandType)){
field = this.getField(parameter.getClass(),"MODIFYUSER");
}
if(filed != null){
ReflectionUtils.setField(field,parameter,SessionUtils.getSession.getUserName());
}
}
来源:oschina
链接:https://my.oschina.net/ffse54s/blog/4411422