Closed eacdy closed 7 years ago
这个地方1.2.15版是pageParameters.put(parameterMapping.getProperty(),parameterObject);这样实现的。现在1.2.17版的实现想解决的问题是遇到DAO的方法只有一个参数且参数是POJO的时候,导致参数和SQL无法匹配的问题。
我想请你把你的DAO方法、POJO和mybatis里SQL查询的代码给我一下,我好在我这把问题还原一下
问题可以复现吧...
不好意思,我这两天出差在外面,等我回去了查一下
我也碰到这个问题了,求大神解决
目前是不支持 query(POJO pojo,PageBounds pageBounds)这样的分页查询???
我也遇到这个问题了,查了老半天,问一下作者解决了吗?
我也遇到这个问题了,
@Test public void testSelectByStateId() { WorkOrderQuery query = new WorkOrderQuery(); query.setTaskSpecIdList(Arrays.asList(new Integer[]{2001, 1001})); List<ResWorkOrderDto> list = resWorkOrderDtoMapper.selectByStateId(query, query.getPageBounds()); query.processRows(list); System.out.println("=============> " + JSON.toJSONString(query)); }
查询实体类
`
public class WorkOrderQuery extends QueryBase
工单状态ID */ private Integer wOrderStateId;
/**
资源ID */ private Integer resId;
/**
任务规格 */ private Integer taskSpecId;
private List
事件状态ID */ private Integer eventStateId;
public Integer getwOrderStateId() { return wOrderStateId; }
public void setwOrderStateId(Integer wOrderStateId) { this.wOrderStateId = wOrderStateId; }
public Integer getResId() { return resId; }
public void setResId(Integer resId) { this.resId = resId; }
public Integer getEventStateId() { return eventStateId; }
public void setEventStateId(Integer eventStateId) { this.eventStateId = eventStateId; }
public Integer getTaskSpecId() { return taskSpecId; }
public void setTaskSpecId(Integer taskSpecId) { this.taskSpecId = taskSpecId; }
public List
public void setTaskSpecIdList(List sqlMapper:
<select id="selectByStateId" resultMap="BaseResultMap"
parameterType="com.fh.task.domain.param.WorkOrderQuery">
select
rwo.wo_id,
rwo.rto_id,
rwo.task_spec_id,
rwo.wo_state_id,
rwo.res_id,
rwo.create_time,
rwo.exc_time,
rwo.complete_time,
rwo.notes,
rwe.event_id,
rwe.event_type_id,
rwe.wo_id as wo_id_e,
rwe.state_id as state_id,
rwe.task_spec_id as task_spec_id_e,
rwe.create_time as create_time_e,
rwe.exc_time as exc_time_e,
rwe.complete_time as complete_time_e,
rwe.exception_info,
rwe.partion_id,
rwe.notes as notes_e
from
res_work_order rwo left join res_wo_event rwe on
rwo.wo_id=rwe.wo_id
where 1=1
异常:
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)
`
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...
@ @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版本
请问这个问题解决了吗?同遇到
@biezhi 更换分页组件解决的
时间太久了,改用Mybatis-pagehelper了。
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?