项目中使用mybatis版本为3.2.8,实体中数组作为参数传递数据,具体环境如下所示。
实体代码片段如下:
public class RptEvDay implements Serializable, Cloneable {
private static final long serialVersionUID = 1L;
private Date start;
private Date end;
private String[] customArray;
private String[] frameArray;
/**
* Constructor.
*/
public RptEvDay() {
super();
}
/**
* Constructor.
* @param id id
*/
public RptEvDay(String id){
super(id);
}
......
}
Mapper配置文件片段如下:
<select id="findList" resultType="RptEvDay">
SELECT a.id,a.cs_id,a.cs_name FROM ln_rpt_ev_day a
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
<if test="customArray != null">
AND a.cs_id in
<foreach collection="customArray" item="customId" index="index" open="(" close=")" separator=",">
#{customId}
</foreach>
</if>
</where>
</select>
执行程序出现如下异常
org.apache.ibatis.reflection.ReflectionException: There is no getter for property named '__frch_customId_0' in 'class com.llg.modules.rpt.entity.day.RptEvDay'
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)
at org.apache.ibatis.reflection.wrapper.BeanWrapper.get(BeanWrapper.java:48)
at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:116)
at com.open.jess.common.persistence.mybatis.interceptor.SQLHelper.setParameters(SQLHelper.java:80)
at com.open.jess.common.persistence.mybatis.interceptor.SQLHelper.getCount(SQLHelper.java:122)
at com.open.jess.common.persistence.mybatis.interceptor.PaginationInterceptor.intercept(PaginationInterceptor.java:68)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:60)
at com.sun.proxy.$Proxy160.query(Unknown Source)
多次尝试后,发现问题还是出现在Mapper配置文件,将Mapper配置文件改写成如下方式(#{customId}-->'${customId}'),问题得以完美解决。
<select id="findList" resultType="RptEvDay">
SELECT a.id,a.cs_id,a.cs_name FROM ln_rpt_ev_day a
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
<if test="customArray != null">
AND a.cs_id in
<foreach collection="customArray" item="customId" index="index" open="(" close=")" separator=",">
'${customId}'
</foreach>
</if>
</where>
</select>