使用MyBatis数组参数出现异常There is no getter for property named '__frch_customId_0'

本文介绍了一个关于MyBatis使用数组作为参数时遇到的问题及解决方案。问题表现为使用数组参数时,Mapper配置文件中的foreach标签无法正确解析数组元素,导致运行时报错。通过将#{customId}

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目中使用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>





评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值