lidatui / mybatis-paginator

A Mybatis plugin, implementation of database paging and sorting.
369 stars 216 forks source link

参数实体类里有数组会报错.版本1.2.17 #9

Closed eacdy closed 7 years ago

eacdy commented 9 years ago

Mapper类:

List selectByConditionPaged(ContentSearchVo contentSearchVo, PageBounds pageBounds);

也就是说, 当参数实体内存有数组时, 会报错,异常栈:

Error querying database. Cause: java.lang.reflect.UndeclaredThrowableException

Cause: java.lang.reflect.UndeclaredThrowableException] with root cause

org.apache.ibatis.reflection.ReflectionException: There is no getter for property named '__frch_item_0' in 'class com.itmuch.icms.content.vo.ContentSearchVo' at org.apache.ibatis.reflection.Reflector.getGetInvoker(Reflector.java:377) at org.apache.ibatis.reflection.MetaClass.getGetInvoker(MetaClass.java:167) at org.apache.ibatis.reflection.wrapper.BeanWrapper.getBeanProperty(BeanWrapper.java:149) at org.apache.ibatis.reflection.wrapper.BeanWrapper.get(BeanWrapper.java:45) at com.github.miemiedev.mybatis.paginator.dialect.Dialect.init(Dialect.java:65) at com.github.miemiedev.mybatis.paginator.dialect.Dialect.(Dialect.java:42) at com.github.miemiedev.mybatis.paginator.dialect.MySQLDialect.(MySQLDialect.java:13) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at com.github.miemiedev.mybatis.paginator.OffsetLimitInterceptor.intercept(OffsetLimitInterceptor.java:73) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:57) at com.sun.proxy.$Proxy47.query(Unknown Source) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104)

问题定位在: com.github.miemiedev.mybatis.paginator.dialect.Dialect类里面的: pageParameters.put(parameterMapping.getProperty(),wrapper.get(prop));这行; wrapper.get(prop)会抛出异常.

如果改成pageParameters.put(parameterMapping.getProperty(),parameterObject);就正常了.

请问这是不是该版本的BUG?

lidatui commented 9 years ago

这个地方1.2.15版是pageParameters.put(parameterMapping.getProperty(),parameterObject);这样实现的。现在1.2.17版的实现想解决的问题是遇到DAO的方法只有一个参数且参数是POJO的时候,导致参数和SQL无法匹配的问题。

我想请你把你的DAO方法、POJO和mybatis里SQL查询的代码给我一下,我好在我这把问题还原一下

eacdy commented 9 years ago

SQL查询:(下载地址: http://code.taobao.org/svn/itmuch/branches/itmuch/icms/branches/icms-biz/src/main/resources/com/itmuch/icms/content/persistence/ContentMapper.xml)

异常: Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named '__frch_specId_0' in 'class com.fh.task.domain.param.WorkOrderQuery' at org.apache.ibatis.reflection.Reflector.getGetInvoker(Reflector.java:380) at org.apache.ibatis.reflection.MetaClass.getGetInvoker(MetaClass.java:170) at org.apache.ibatis.reflection.wrapper.BeanWrapper.getBeanProperty(BeanWrapper.java:152) `

aknowles commented 8 years ago

It is caused by the copying of parameters into the pageParameters in Dialect.java (init() method). Not all mapped parameters are directly binding to the parameterObject. In the case of *Example objects and the for-each criteria, these are bound in directly (thus the _frch prefix), and will not directly bind the parameterObject (not sure why they didn't use the _e[0].value or something like that, but that's another discussion). In this case you hack around the issue by just adding a try/catch around: pageParameters.put(parameterMapping.getProperty(), wrapper.get(prop)); Would be a bit nicer to check if the wrapper has the property instead, but that would be best implemented inside of wrapper itself (because of PropertyTokenizer). It would also be nice if there was any indication in the mapper that it was a directly bound parameter too. Alternatively you could just add an if clause around having the prefix from ForEachSqlNode.ITEM_PREFIX...

654894017 commented 8 years ago

@ @miemiedev

mybatis-paginator 1.2.17 mybatis 3.4.1 mybais-spring 1.3.0

Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named '__frch_criterion_1' in 'class com.xxx.xxxx.storage.utils.GenericCriteria' at org.apache.ibatis.reflection.Reflector.getGetInvoker(Reflector.java:409) at org.apache.ibatis.reflection.MetaClass.getGetInvoker(MetaClass.java:164) at org.apache.ibatis.reflection.wrapper.BeanWrapper.getBeanProperty(BeanWrapper.java:162) at org.apache.ibatis.reflection.wrapper.BeanWrapper.get(BeanWrapper.java:49) at com.github.miemiedev.mybatis.paginator.dialect.Dialect.init(Dialect.java:65) at com.github.miemiedev.mybatis.paginator.dialect.Dialect.(Dialect.java:42) at com.github.miemiedev.mybatis.paginator.dialect.MySQLDialect.(MySQLDialect.java:13) ... 20 more

1.2.17版本分页报错 改成1.2.15正常使用 spring 4.0.9版本

hellokaton commented 8 years ago

请问这个问题解决了吗?同遇到

654894017 commented 8 years ago

@biezhi 更换分页组件解决的

eacdy commented 7 years ago

时间太久了,改用Mybatis-pagehelper了。