<select id="queryRecord" resultType="Map">
select * from ${tableName}
<where>
<if test="keysRecord!=null ">
<foreach collection="keysRecord.entrySet()" separator="AND" index="k" item="entry">
<if test="entry.value != null and entry.value != ''" >
${entry.key} = #{entry.value}
if>
foreach>
if>
where>
select>
Caused by: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'entry.value != null and entry.value != '''. Cause: org.apache.ibatis.ognl.OgnlException: value [java.lang.IllegalAccessException: Class org.apache.ibatis.ognl.OgnlRuntime can not access a member of class java.util.HashMap$Entry with modifiers "public final"]
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
猜测就是Map中entry.value值拿不到,拿不到里面报了权限不允许访问错误。想不明白为何会拿不到权限,是mybatis的这个test表达式使用反射导致的问题吗
这个问题是由于foreach不支持entry.value != null和entry.value != ''这种条件判断方式引起的,可以修改test条件:
${entry.key} = #{entry.value}