MybatisPlus乐观锁插件使用(拦截器)

从拦截器代码看得出与之前文章写的实现思路一样,拦截器会在更新操作时以查询时查到的version值为条件,并设置新的version值为version+1,这样一来如果version值存在即没有被修改就可以更新成功。

 public Object intercept(Invocation invocation) throws Throwable {
        Object[] args = invocation.getArgs();
        MappedStatement ms = (MappedStatement)args[0];
        if (SqlCommandType.UPDATE != ms.getSqlCommandType()) {
            return invocation.proceed();
        } else {
            Object param = args[1];
            if (param instanceof Map) {
                Map map = (Map)param;
                Object et = map.getOrDefault("et", (Object)null);
                if (et != null) {
                    String methodId = ms.getId();
                    String methodName = methodId.substring(methodId.lastIndexOf(".") + 1);
                    TableInfo tableInfo = TableInfoHelper.getTableInfo(et.getClass());
                   

猜你喜欢

转载自blog.csdn.net/qq_29569183/article/details/111920983