gpt4 book ai didi

java - Mybatis 无 Getter 属性

转载 作者:行者123 更新时间:2023-12-02 08:07:32 25 4
gpt4 key购买 nike

我正在使用 Mybatis 3.2.6 并实现自定义结果处理程序。我之前已经使用简单的数据类型参数完成了此操作,并且没有遇到任何问题。这次我需要传递几个参数...我使用的签名是

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
* &quot;code&quot; 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);

工作得很好,但是当我通过 session 上的选择调用时,出现以下异常。

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 来解决此问题。

关于java - Mybatis 无 Getter 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24070582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com