Giter Club home page Giter Club logo

Comments (11)

yangyang0507 avatar yangyang0507 commented on May 16, 2024

多谢反馈,我们会尽快调整!

from mybatis-plus.

yuxiaobin avatar yuxiaobin commented on May 16, 2024

这个问题在git.oschina上dev分支已修复,将在下个版本解决

from mybatis-plus.

kevin82008 avatar kevin82008 commented on May 16, 2024

2.0.6-jdk8 里面,在同一个会话里,多次调用同一个语句,还是会异常。
比如原始语句是 update xx set version = ? and xx = ? where id = ?
处理后的语句是 update xx set version = ? and xx = ? where version = ? and id = ?
第一次调用时,前面的version的值会+1,后面的version会添加一个参数;
第二次调用时,不会处理(因为prepare在同一个会话里根据sql有缓存,第二次调用直接取缓存,不会调用插件再处理)
应该还是需要在executor的地方拦截,prepare不行。

from mybatis-plus.

yuxiaobin avatar yuxiaobin commented on May 16, 2024

非常感谢,已经着手查看该问题了

from mybatis-plus.

kevin82008 avatar kevin82008 commented on May 16, 2024

提个思路吧,还是拦截StatementHandler,但是换成拦截getBoundSql这个方法,
处理sql的时候,不能添加额外的参数,版本号的值需要直接设置到sql语句里面去。
比如原来有 set version = ? 就改成 set version = ? + 1,没有,就改成 set version = version + 1
条件里如果原来有 version = ? 就不处理,没有就处理成 version = 具体的值(具体的根据version的类型在versionHandler里处理)
getBoundSql会在prepare之前处理,应该可以这样处理。

from mybatis-plus.

kevin82008 avatar kevin82008 commented on May 16, 2024

顺便提一句,如果@Version注解是在父类上,最新版本还是不管用的

from mybatis-plus.

qmdx avatar qmdx commented on May 16, 2024

@kevin82008 抱歉! 请等一等我们的正式版 2.0.6

from mybatis-plus.

yuxiaobin avatar yuxiaobin commented on May 16, 2024

@kevin82008 Mybatis的plugin仅支持:
MyBatis allows you to intercept calls to at certain points within the execution of a mapped statement. By default, MyBatis allows plug-ins to intercept method calls of:

Executor (update, query, flushStatements, commit, rollback, getTransaction, close, isClosed)
ParameterHandler (getParameterObject, setParameters)
ResultSetHandler (handleResultSets, handleOutputParameters)
StatementHandler (prepare, parameterize, batch, update, query)

http://www.mybatis.org/mybatis-3/configuration.html#plugins

from mybatis-plus.

kevin82008 avatar kevin82008 commented on May 16, 2024

我试过,可以拦截getBoundSql方法,不过官方声明上确实没有

from mybatis-plus.

yuxiaobin avatar yuxiaobin commented on May 16, 2024

@kevin82008 这么神奇,不过不是很推荐,万一官方版本升级了,去掉了这个,那不就GG了

from mybatis-plus.

huayanYu avatar huayanYu commented on May 16, 2024

@kevin82008 我试过拦截getBoundSql,确实可以. 但是普通模式就不能用了.
这个插件主要是我在负责,确实没什么好的思路了. 在Executor上拦截有很多问题的.
如果你要用重用模式不然手动复制一下自己拦截getBoundSql.

from mybatis-plus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.