java Mybatis Xml Sql 中 IN 的两种写法: #{item} => #{collection[${index}]}

今天使用到一个开源框架JeePlus, 它里边的 Page 是自己封装的
在获取 count 时, 他需要对 已经生成的sql 做一层count() 封装

public class SQLHelper {
	public static int getCount(
		final String countSql = "select count(1) from (" + countsql + ") tmp_count";
	}
}

然后通过下面方法 对SQL参数(?) 设值

public static void setParameters(
}

然后现在我需要对他xml自动生成的sql添加一个 IN 的操作
如下:

<select id="findList" resultType="XX" >
		SELECT
			<include refid="smpStoreOrderColumns"/>
		FROM smp_store_order a
		<where>
			a.create_by in
			<foreach collection="underUserIds" item="id" index="index" separator="," open="(" close=")">
				#{id}
			</foreach>
			and a.del_flag = '0'
			${dataScope}
		</where>
	</select>

跟平时一样, 我使用了 #{id} 进行 值的获取, 但是在这个框架中,他是不支持的:


Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named '__frch_id_0' in 'class com.jeeplus.modules.tongji.order.entity.SmpStoreOrder'
	at org.apache.ibatis.reflection.Reflector.getGetInvoker(Reflector.java:375)
	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 org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:122)
	at com.jeeplus.core.persistence.interceptor.SQLHelper.setParameters(SQLHelper.java:79)
	at com.jeeplus.core.persistence.interceptor.SQLHelper.getCount(SQLHelper.java:131)
	at com.jeeplus.core.persistence.interceptor.PaginationInterceptor.intercept(PaginationInterceptor.java:104)
// 去 SQLHelper.java:79 看看
// propertyName = __frch_id_0
value = metaObject == null ? null : metaObject.getValue(propertyName);
// 原来这里解析不了我上边写的#{id}  但是我又不知道为什么, 进去看看
// 此处省略一万字

切换一下写法

<foreach collection="underUserIds" item="id" index="index" separator="," open="(" close=")">
	#{id}
</foreach>
<foreach collection="underUserIds" item="id" index="index" separator="," open="(" close=")">
	#{underUserId[${index}]}
</foreach>

成功执行 !

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值