使用mybatis的拦截器机制可以在sql的插入及更新时设置创建人和更新人
https://www.jianshu.com/p/0a72bb1f6a21
@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());
}
}
以上是 使用mybatis的拦截器机制可以在sql的插入及更新时设置创建人和更新人 的全部内容, 来源链接: utcz.com/z/518516.html