Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mybatis添加分页拦截器后出现的取值问题 #18

Closed
460541922github opened this issue Jul 26, 2017 · 12 comments
Closed

mybatis添加分页拦截器后出现的取值问题 #18

460541922github opened this issue Jul 26, 2017 · 12 comments
Labels

Comments

@460541922github
Copy link

问题代码如下:

#{item}

由于项目中用到了分页拦截器,一旦有分页的sql中,用#{}获取值都会报错( org.apache.ibatis.binding.BindingException: Parameter '__frch_item_0' not found.),换成${}这种方式就好了,请问什么原因?

@abel533
Copy link
Contributor

abel533 commented Jul 26, 2017

这个错只有 foreach 会出现,你分页用的什么版本?

@460541922github
Copy link
Author

460541922github commented Jul 26, 2017

if(page.getAutoCount() == 0) {
                    queryArgs[0] = this.clone(ms, ms.getBoundSql(parameterObject), page);
                }

                Future listFuture1 = this.call(new Callable() {
                    public List call() throws Exception {
                        return (List)invocation.proceed();
                    }
                }, this.asyncCount);
                page.setResult((List)listFuture1.get());
                if(page.getAutoCount() == 0) {
                    Callable countTask = new Callable() {
                        public Object call() throws Exception {
                            Configuration configuration = ms.getConfiguration();
                            String countSql = PageLimitInterceptor.this.dialect.getCountSql(boundSql.getSql());
                            if(PageLimitInterceptor.logger.isDebugEnabled()) {
                                PageLimitInterceptor.logger.debug("生成count语句: " + countSql);
                            }

                            PreparedStatement countStmt = executor.getTransaction().getConnection().prepareStatement(countSql);
                            BoundSql countBS = PageLimitInterceptor.this.dialect.getBoundSql(configuration, countSql, boundSql);
                            PageLimitInterceptor.this.setParameters(countStmt, configuration, countBS, parameterObject);
                            ResultSet rs = countStmt.executeQuery();
                            long count = 0L;
                            if(rs.next()) {
                                count = rs.getLong(1);
                            }

                            rs.close();
                            countStmt.close();
                            return Long.valueOf(count);
                        }
                    };
                    Future countFuture = this.call(countTask, this.asyncCount);
                    page.setTotalCount(((Long)countFuture.get()).longValue());
                }

                return listFuture1.get();

问题就在这里,你所说的分页版本我暂时不清楚,mybatis 是3.4.1 的,拦截器是自己写的,没有用第三方的

@abel533
Copy link
Contributor

abel533 commented Jul 26, 2017

分页插件的版本?

@abel533
Copy link
Contributor

abel533 commented Jul 26, 2017

不用提供版本了,这个插件不是我写的,有这个问题很正常。。

我写的分页插件地址:https://github.com/pagehelper/Mybatis-PageHelper

@460541922github
Copy link
Author

是的

@460541922github
Copy link
Author

请问我这个啥原因么,我想知道

@abel533
Copy link
Contributor

abel533 commented Jul 26, 2017

没有处理foreach生成的动态参数。

@460541922github
Copy link
Author

是mybatis的问题 还是我的拦截器的问题?这个是我之前网上找的!另外处理foreach生成的动态参数的代码能告诉我位置么

@abel533
Copy link
Contributor

abel533 commented Jul 26, 2017

拦截器的问题

@460541922github
Copy link
Author

请教你另外一个问题,前天下载了一个阿里的开发人员注意手册,里面说到update同一个表的的同一条记录时候更新的字段的数目多少影响效率,和我自己理解的就不一样(应该是和数目没关系),update实际做的就是delete 和insert

@abel533
Copy link
Contributor

abel533 commented Jul 26, 2017

这个问题只有大量测试才能看出来效果,不清楚数据库底层如何实现的update。

@460541922github
Copy link
Author

哦哦,谢谢了哈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants