我正在使用Mybatis 3.2.6并实现自定义resulthandler。在使用简单的数据类型参数之前,我已经完成了此操作,并且没有任何问题。这次我需要传递几个参数...我正在使用的签名是
session.select(statement, parameter, handler);
对于参数,我创建了一个简单的POJO来轻松发送所需的信息。如下:
public class DifferenceParam {
private int current;
private int compare;
private String table;
private String comparator;
/**
* Constructor excluding comparator. Will default a value of
* "code" to compare content on, e.g., <br/>
* {@code select * from a minus select * from b where a.code = b.code } <br/>
* @param table
* @param current
* @param compare
*/
public DifferenceParam(String table, int current, int compare) {
this(table, "code", current, compare);
}
/**
* Constructor providing a specific column to compare on, e.g. <br/>
* {@code select * from a minus select * from b where a.[comparator] = b.[comparator] } <br/>
* @param table
* @param comparator
* @param current
* @param compare
*/
public DifferenceParam(String table, String comparator, int current, int compare) {
this.table = table;
this.comparator = comparator;
this.current = current;
this.compare = compare;
}
/** Appropriate setters and getters to follow **/
}
目前,处理程序的实现是无关紧要的,因为我已经提前得到了异常。我正在执行的查询是:
<select id="getCodeSetModifications" parameterType="DifferenceParam" resultType="Code">
select *
from
(
select * from ${param.table} where revision_seq = #{param.current}
minus
select * from ${param.table} where revision_seq = #{param.compare}
) a, ${param.table} b
where a.${param.comparator} = b.${param.comparator}
and b.revision_seq = #{param.compare}
</select>
这也是界面
public List<Code> getCodeSetModifications(@Param("param") DifferenceParam param);
我遇到的问题是通过映射器执行,例如
session.getMapper(DifferenceParam.class);
工作正常,但是当我在会话上通过选择调用时,出现以下异常。
Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'param' in 'class com.mmm.his.cer.cerval.uidifference.map.param.DifferenceParam'
Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'param' in 'class com.mmm.his.cer.cerval.uidifference.map.param.DifferenceParam'
我已经尽力调试Mybatis,但没有运气。
提前致谢...
最佳答案
当您使用session.getMapper(DifferenceParam.class);
时,mybatis将查找@Param
批注并在查询中使用它的值。
调用session.select(statement, parameter, handler);
时,不会发生这种映射。
尝试将public DifferenceParam getParam() { return this; }
添加到DifferenceParam以解决此问题。